可以参考以下代码,自己修改。
#! /usr/bin/env python
#coding=utf-8
#百度推送 by tools.bugscaner.com
import httplib
data = open("sitemap.txt","r").read()
allurls = data.split("\n")
nbs = len(allurls)
if nbs/2000*2000 != nbs:
all = nbs/2000 + 1
else:
all = nbs/2000
for x in range(1,all+1):
urlinfos ="\n".join(allurls[(x-1)*2000:x*2000])
headers = {"Content-Type":"application/x-www-form-urlencoded"}
conn = httplib.HTTPConnection("data.zz.baidu.com")
try:
conn.request("POST","/urls?site=tools.bugscaner.com&token=QesN4asTDZH1bjfq",urlinfos,headers)
httpres = conn.getresponse()
html = httpres.read()
print html
except Exception,e:
print e
注意,这是python2.7版本的推送代码。
来源:互联网
想推广的话挺好,而且可以在页面中加入百度提交代码,这样有人访问或提交内容,就会自动推送到百度。我不想推广,所以就没弄。你可以查一下百度站长工具。
已经在用了,主动推送是针对大站保护原创及时收录的,不过好像还是sitemap更好用些。
感谢博主分享!
非常不错!