因为百度批量推送脚本的时候最大只能推送2000条,所以要有一个分文件脚本进行辅助。
#coding=utf8 import requests url = ‘http://data.zz.baidu.com/urls?site=newhouse.nj.house365.com&token=h5NoG7bfjR2Yk2sq’ for i in range(1,51): headers = { ‘Content-Type’: ‘text/plain’, } urls=[] with open(‘url’+str(i)+’.txt’) as f: for line in f: urls.append(line.strip()) cont = ‘ ’.join(urls) r = requests.post(url, cont) print r.text
代码如下图:
#coding:utf-8 p=1 q=0 with open (‘url.txt’) as f: for link in f: url=link.strip() txt=open(‘url’+str(p)+’.txt’,’a’) txt.write(url+’ ’) q=q+1 if q%2000==0: p=p+1
代码如下图: