百度主动推送,虽然每天总推送的条数没有了限制,但是,根据实测,每次推送的条数是2000条,如果数据量大的话,要不停的执行程序,此时有两种解决方法,一种是在生成链接文件的时候就加上条数限制,另外一种就是对链接文件进行切割处理,然后挨个推送。
#coding:utf-8 import requests,time import sys reload(sys) sys.setdefaultencoding('utf-8') print 'The file is being generated.' num = 0 f = open('%s.txt' %num,r'a+') for i,line in enumerate(open('url.txt')): f.write(line.strip()+'\n') if i % 1000 == 999: f.close() num += 1 f = open('%s.txt' %num,r'a+') f.close() print 'The file generation is complete,Please wait 3 seconds.' time.sleep(3) print 'Pushing data.' for i in range(0,num+1): headers = {'Content-Type':'text/plain'} url = 'http://data.zz.baidu.com/urls' params = {'site':'www.jd.com','token':'***','type':'original'} r = requests.post(url,params=params,headers=headers,data=open('%s.txt'%i,r'rb').read()) print r.content time.sleep(10) print 'The data push is complete'