当Python遇上SEO,利用python向百度推送网站链接,提
做网站的人一般都很关注网站的收录量,而收录量就需要蜘蛛去爬取,而爬取则需要去提交。
而百度提供了api提交的方法。
用python进行提交的话,我选择的是post提交。
POST /urls?site=“自己网站的token” # 这里是site后面那一段带网站的,[color=#f95d5d][font=tahoma, PingFangSC, "]site[/font][/color][color=#666666][font=tahoma, PingFangSC, "]=[/font][/color][color=#666666][font=tahoma, PingFangSC, "]https://zjzdmc.top[/font][/color][color=#666666][font=tahoma, PingFangSC, "]&[/font][/color][color=#f95d5d][font=tahoma, PingFangSC, "]token[/font][/color][color=#666666][font=tahoma, PingFangSC, "]=xxxxxxxx,并非是整个[/font][/color][color=#666666][font=tahoma, PingFangSC, "]接口调用地址。[/font][/color] User-Agent: curl/7.12.1 Host: data.zz.baidu.com Content-Type: text/plain Content-Length: 83
这个第一行的token请换成自己的。
私信小编01即可获取大量Python学习资源
http://www.example.com/1.htmlhttp://www.example.com/2.html
这个是提交示例,也就是说一个一行。
{ "remain":99998, "success":2, "not_same_site":[], "not_valid":[] }
这个是返回信息,那么如何去写就一目了然了。
Python源码:
import requestsimport reimport time headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36,', 'Host': 'data.zz.baidu.com', 'Content-Length':'83'} print("*"*30) print('links.txt示例:\nhttps://xxxxx.html\nhttps://xxxxx.html\nhttps://xxxxx.html\nhttps://xxxxx.html') print("*"*30) print('api示例:\nhttp://data.zz.baidu.com/urls?site=xxxxxxxxxxx') push_num = 1while push_num < 9999: if push_num == 1: answer = input("请问你是否已经将链接填入links.txt,api填入api.txt中呢,如果是则回答1\n") if answer == '1': try: with open('links.txt', 'r') as links: links = links.read() except FileNotFoundError: print("links.txt文件不存在") try: with open('api.txt', 'r') as api: api = api.read() except FileNotFoundError: print("links.txt文件不存在") def thinklink(links, api): if links == '': print("links.txt文件为空") else: if api == '': print('api.txt为空') else: try: html_result = requests.post(api, headers=headers, timeout=5, data=links).text return html_result except: return print("失败") push_result = thinklink(links, api) print('提交完成:'+push_result) surplus_push_num = re.findall('"remain":(.*),"', push_result) surplus_push_num = surplus_push_num.pop() print('剩余' + surplus_push_num + '次提交机会') else: print("请将内容填充!5秒钟后自动关闭") time.sleep(5) break print('*'*30) new_answer = input("是否还需要提交,如果是的话请先去更改一下相应文件,如果是请输入1,如果否请输入0\n") if new_answer == '0': print("提交结束,5秒钟后自动关闭") time.sleep(5) break push_num += 1 print("现在开始第"+str(push_num)+'次提交')
需要在python文件新建两个txt文件,分别放token和链接。
然后其他人就可以直接双击打开python文件进行提交了。如果有什么疑问可以直接问。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。