标签:code params requests new headers api list xxxx end
import requests,json import urllib url=‘http://apis.baidu.com/txapi/mvtp/meinv‘ path=‘F:\\screen\\baidu\\‘ headers={‘apikey‘:XXXX} page_links=[] names=[] def get_url(num): payload={‘num‘:num} page=requests.get(url,params=payload,headers=headers) data=page.json() for i in range(1,num): page_links.append(data[‘newslist‘][i][‘picUrl‘]) names.append(data[‘newslist‘][i][‘title‘]) def get_file(links,names): for link,name in zip(links,names): save_img(link,name) def save_img(url,name): urllib.request.urlretrieve(url,path + name+‘.‘+url.split(‘.‘)[-1]) print (‘Done‘) get_url(10) get_file(page_links,names)
标签:code params requests new headers api list xxxx end
原文地址:http://www.cnblogs.com/zg019/p/6051390.html