从照片网站pexels批量爬取照片
调试中,未成功。
from bs4 import BeautifulSoup import requests headers={ #'User-Agent':'Nokia6600/1.0 (3.42.1) SymbianOS/7.0s Series60/2.0 Profile/MIDP-2.0 Configuration/CLDC-1.0' 'accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36' } urls=['https://www.pexels.com/search/book/page={}'.format(i) for i in range(1,10)] list=[] for url in urls: wb_data=requests.get(url,headers=headers) #print(wb_data) soup=BeautifulSoup(wb_data.text,'lxml') imgs=soup.select('body>div.page-wrap>div.l-container>div.photos>article>a.js-photo-link>img') print(imgs) for img in imgs: photo=img.get('src') print(photo) list.append(photo) path='C://Users/Administrator/Desktop/aa' for item in list: data=requests.get(item,headers=headers) print(data) fp=open(path+item.split('?')[0][-10:],'wb') fp.write(data.content) fp.close()