import requests
import os
from lxml import etree

url = 'https://www.yjwujian.cn/media/#/pic'
headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36'
}
response = requests.get(url=url, headers=headers)
html = etree.HTML(response.text)
img = html.xpath('//div[@class="item"]/@data-origin')
os.mkdir('./yongjie')  # 创建文件夹
for data in img:
    data1 = str(data)
    data_1 = requests.get(url=data1,headers=headers).content
    file_name = str(data1).split('/')[-1].split('.')[0]
    file_path = './yongjie/'+file_name+'.jpg'
    with open(file_path,'wb') as f:
        f.write(data_1)

运行结果:

image.png

最后修改:2022 年 08 月 31 日
如果觉得我的文章对你有用,请随意赞赏