栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python 自动推送百度收录脚本

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python 自动推送百度收录脚本

Python 自动推送百度收录脚本

版权属于:瞌学家 所有,转载请注明出处
本文链接:https://www.songonline.top/archives/185/
友情提示: 如果文章部分链接出现404,请留言或者联系博主修复。

import requests
import re


# 根据站点地图获取链接
def get_urls(sitemap):
    response = requests.get(url=sitemap)
    urls = re.findall('(.*?)', response.text)
    return urls


# 推送百度 (参数:网站网址,token,网站站点地图)
def submit_baidu(site: str, token: str, sitemap: str):
    msg = []
    url_list = get_urls(sitemap)
    response = requests.post(url=f'http://data.zz.baidu.com/urls?site={site}&token={token}',
                             headers={
                                 'User-Agent': 'curl/7.12.1',
                                 'Host': 'data.zz.baidu.com',
                                 'Content-Type': 'text/plain',
                                 'Content-Length': '83'
                             },
                             data='n'.join(url_list)

                             )
    if response.status_code == 200:
        data = response.json()
        msg.append(f"成功推送的url条数 {data.get('success')}")
        msg.append(f"当天剩余的可推送url条数 {data.get('remain')}")
        msg.append(f'今日推送的url列表:')

        for url in url_list:
            msg.append(f"{url}")
        if data.get('not_same_site') is not None:
            msg.append('由于不是本站url而未处理的url列表:')
            for url in data.get('not_same_site'):
                msg.append(f"{url}")
        if data.get('not_valid') is not None:
            msg.append('不合法的url列表:')
            for url in data.get('not_valid'):
                msg.append(f"{url}")

    else:
        msg.append(f'推送失败n{response.json()}')
    return msg


if __name__ == '__main__':
    try:
        info = submit_baidu(site='https://www.songonline.top', token='',
                            sitemap='https://www.songonline.top/sitemap.xml')
        print('n'.join(info))
    except Exception as e:
        print(e)

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/769074.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号