Paging crawling Saito birds pictures

#简单爬取斋藤飞鸟图片
import requests
import time
from lxml import etree
# from requests.exceptions import RequestException
def get_one_page(url):
headers={
'User - Agent':'Mozilla / 5.0(Windows NT 10.0;Win64;x64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 75.0.3770.100Safari / 537.36',
}
r=requests.get(url,headers=headers)
# if r.status_code==200:
# return r.text
# return None
# except RecursionError:
# return None
contend=r.text
html=etree.HTML(contend)
src_list=html.xpath('//img/@src')
alt_list=html.xpath('//div[@class="prop"]/text()')
for src,alt in zip(src_list,alt_list):
filename=src[48:]
print('正在爬取第%d页'%(d/30))
print('正在保存图片'+filename)
r = requests.get(src,headers=headers)
with open('斋藤飞鸟图片//'+filename,'wb') as f:
f.write(r.content)

def main(d):
url='https://movie.douban.com/celebrity/1329640/photos/?type=C&start=%d&sortby=like&size=a&subtype=a' %(d)
# print(r.text)
print(get_one_page(url))

if __name__=='__main__':
d = 0
while True:
d = d + 30
if d >= 500:
break
main(d)
time.sleep(0.5)

Guess you like

Origin www.cnblogs.com/L-flyPython3/p/11613294.html