In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how Python can push Baidu links. Xiaobian thinks it is quite practical, so share it with you for reference. I hope you can gain something after reading this article.
Through the code to achieve grab a page in the personal blog specified article link, and batch push the link to baidu webmaster platform, play the purpose of rapid inclusion.
import sysimport requestsfrom bs4 import BeautifulSoup#Push Baidu crawler def push_page(url): headers = { 'User-Agent': 'curl/7.12.1', 'Host': 'data.zz.baidu.com', 'Content-Type': 'text/plain', 'Content-Length': '83' } urls = "http://data.zz.baidu.com/urls? site=https://www.lyshark.com&token=xxxxxxx" try: html = requests.post(urls, headers=headers, data=url, timeout=5).text push_status = eval(html)['success'] if push_status == 1: return 1 else: return 0 except: return 0#Get path def get_page(page): html = requests.get(page,timeout=5).text try: bs = BeautifulSoup(html,"html.parser") ret = bs.select('div[class="container"] div[class="row"] h3[class="post-title"] a') for item in ret: push_url = item.get('href') push_ref = push_page(push_url) print("push: {} --> status: {}".format(push_url,push_ref)) return 1 except: return 0if __name__ == "__main__": arg = sys.argv get_page(arg[1])
supplementary
Baidu currently provides automatic submission links and manual submission links in two ways, of which automatic submission is divided into active push, automatic push and sitemap three forms, according to Baidu's argument, active push effect is best, Baidu webmaster platform background also provides curl, php, ruby push sample code but does not provide python code, there are few ready-made python version active push code online (The only ones are a little buggy and need to be fixed), and now I'm posting the active push python code I'm currently using.
#encoding:utf-8import httplibdef tuisong(): filecontents = open( "urls.txt", "r" ).read() //urls.txt is the URL file to be pushed, one per line url = "/urls? site= domain name (without http)&token= token (you can see it in the background of your own Baidu webmaster platform)" conn = httplib.HTTPConnection('data.zz.baidu.com') conn.request(method="POST", url=url, body=filecontents) response = conn.getresponse() baiduresult = response.read() conn.close() return baiduresult if __name__=="__main__": ts=tuisong() print ts
After pushing, it will return the relevant code!
Here's what I did with requests, more succinctly:
import requestsdef tuisong(self): url = "/urls? site= domain name (without http)&token= token (you can see it in the background of your own Baidu webmaster platform)" filecontents = {'file': open ('urls.txt', 'rb')} #urls.txt is the URL file to push, one per line r=requests.post("http://data.zz.baidu.com"+url, files=filecontents) baidusult ="Push succeeded, result is %s \n" %(r.text) return baiduresult if __name__=="__main__": ts=tuisong() print(ts) on "Python how to achieve push Baidu link" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.