当前位置:首页 > 二营长SEO > 百度主动推送Python代码

百度主动推送Python代码

作者:heziliang 发布时间:2016-12-11 点击:

百度主动推送Python三种实现方式

#coding:utf-8
import requests,pycurl,StringIO
#curl
curl -H 'Content-Type:text/plain' --data-binary @urls.txt "http://data.zz.baidu.com/urls?site=domain&token=yourtoken&type=original"

#requests headers = {'Content-Type':'text/plain'} url = 'http://data.zz.baidu.com/urls' params = {'site':'domain','token':'yourtoken','type':'original'} r = requests.post(url,params=params,headers=headers,data=open('urls.txt',r'rb').read()) print r.content
#pycurl
url = 'http://data.zz.baidu.com/urls?site=domain&token=yourtoken'
c = pycurl.Curl()
c.setopt(c.URL,url)
c.setopt(pycurl.HTTPHEADER,['Content-Type:text/plain'])
c.setopt(c.POST,1)
c.setopt(c.POSTFIELDS,open('urls.txt',r'rb').read())
b = StringIO.StringIO()
c.setopt(c.WRITEFUNCTION, b.write)
c.perform()
info = b.getvalue()
print info

github:https://github.com/hzlRises/hzlgithub/blob/master/Push/push.py

邮箱:techseo.cn@gmail.com,欢迎交流。
上一篇:没有了      下一篇:根据标题调取相关文章实现方法