import requests
from lxml import etree
url='https://zhuanlan.zhihu.com/p/408232419'
headers={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36 Edg/96.0.1054.29'
}
response=requests.get(url, headers=headers)
response.encoding='utf-8'
selector=etree.HTML(response.text)
root='D:/天下3/pictuers'
for i in range(1,64):
url=selector.xpath('//div[@class="RichText ztext Post-RichText css-hnrfcf"]/figure[{}]/img/@data-original'.format(i))
for img_url in url:
root='D:/pic/'
path = root + img_url.split('/')[-1]
r = requests.get(img_url)
with open(path, 'wb') as f:
f.write(r.content)
f.close()
print("文件保存成功")
爬取知乎图片
最新推荐文章于 2023-11-10 17:33:32 发布