需要在文件目录下面建一个urls.txt的文件,将所有要推送的url放到文本里。然后运行下面的脚本。
import requests def baidu_push(url, token): headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3' } params = { 'site': url, 'token': token } r = requests.post("http://data.zz.baidu.com/urls", headers=headers, params=params) return r.text with open("urls.txt", "r") as file: urls = file.readlines() for url in urls: print(baidu_push(url.strip(), "your_token"))
标签:baidu,headers,python,url,token,params,urls,推送,百度 From: https://www.cnblogs.com/dashenblog/p/17084546.html