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)
时间: 2024-10-09 23:30:13