首页 » 编程开发 » Python » 正文

Python之百度URL链接主动提交收录代码实例

百度链接提交功能:链接提交工具为您提供多种方式向百度提交数据,帮助百度发现并了解您网站上的网页和网站结构,优化收录

百度url提交数据接口的代码示例只有curl、php、ruby共三种方式,下面是我自己摸索的python写法,分享给大家:

if os.path.isfile(‘output/article_update.txt’):
filecontents = open(“output/article_update.txt”,”r”).read()
othertoken=’b6f1KBXy8rMTj5wd’
URL = “/urls?site=%s&token=%s” % (‘www.xxx.com’,othertoken)
headerdata = {“Host”:”data.zz.baidu.com”,’Content-Type’ : ‘text/plain’}
conn = httplib.HTTPConnection(“data.zz.baidu.com”,80)
conn.request(method=”POST”,url=URL,body=filecontents,headers = headerdata)
response = conn.getresponse()
baiduresult = response.read()
conn.close()

之前我设置了参数“Content-Length: 83 ”,结果从返回的接口看,一直只能成功2条,检查时才发现这个参数如果不用post方式,是不能随便乱用的。

返回的结果:

{
    "remain":4999980,
    "success":20,
    "not_same_site":[],
    "not_valid":[]
}

本文共 3 个回复

  • Johny Jackson 2018/01/10 06:01

    I'm no longer certain the place you are getting your info, however great topic. I needs to spend some time finding out much more or understanding more. Thank you for magnificent info I was on the lookout for this information for my mission.

  • Johny Jackson 2018/01/15 04:10

    What's Taking place i'm new to this, I stumbled upon this I've discovered It positively useful and it has helped me out loads. I hope to contribute & help other users like its aided me. Great job.

  • Johny Jackson 2018/01/18 04:31

    obviously like your web-site however you need to take a look at the spelling on quite a few of your posts. A number of them are rife with spelling problems and I in finding it very bothersome to tell the truth on the other hand I'll surely come back again.

回复 Johny Jackson 取消