本帖最后由 qqilin1213 于 2020-11-15 10:09 编辑
[Asm] 纯文本查看 复制代码 import requests
from lxml import etree
import os
import re
# //div[[url=home.php?mod=space&uid=341152]@Class[/url] = 'list clearfix']//h3
url = 'https://www.dpm.org.cn/lights/royal.html'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/86.0.4240.193 '
'Safari/537.36 '
}
response_data = requests.get(url, headers=headers).text
html = etree.HTML(response_data)
images_coup = html.xpath("//div[@class = 'pic']//@href")
image_title = html.xpath("//div//img/@title/text()")
print(image_title)
for i in images_coup:
url = i
image_url = "https://www.dpm.org.cn" + url
# print(image_url)
response_images = requests.get(image_url, headers=headers).text
# print(response_images)
html1 = etree.HTML(response_images)
image_data = html1.xpath("//img[[url=home.php?mod=space&uid=346784]@style[/url] ='visibility: visible;width: 100%;']/@src")
# print(image_data[0])
image_url = requests.get(image_data[0], headers=headers)
# print(image_url)
save = './壁纸/'
address_save = str(save)
# 判断文件夹是否存在,然后自己创建
count = 1
if not os.path.exists(address_save):
os.makedirs('./壁纸/')
else:
with open(address_save + '/.png', 'wb') as f:
f.write(image_url.content) |