首先需要在百度站长平台把网站通过验证。
import requests
def push_urls(url, urls):
headers = {
'User-Agent': 'curl/7.12.1',
'Hos': 'data.zz.baidu.com',
'Content-Type': 'text/plain',
'Content-Length': '83'
}
try:
html = requests.post(url, headers=headers, data=urls, timeout=5).text
return html
except:
return '{"success": 0}'
url = 'http://data.zz.baidu.com/urls?site=xxxxxx&token=xxxxxx' # 推送接口
urls = 'xxx' # 推送的文章链接
push = push_urls(url, urls)
push_status = eval(push)['success']
if push_status == 1:
print('推送成功')
else:
print('请求错误')