[Python] 纯文本查看 复制代码 import requests
import re
import os
url = 'https://www.bizhi88.com/3840x2160/'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.0.0 Safari/537.36'
}
response = requests.get(url=url, headers=headers)
response.encoding = 'utf8'
html_info = re.findall('<a href="(.*?)" title="(.*?)" target="_blank" class="img" style="(.*?)"', response.text)
num = 0
for link, title, style in html_info:
num = num + 1
if num == 1:
continue
link_url = 'https://www.bizhi88.com' + link
response2 = requests.get(url=link_url, headers=headers)
response2.encoding = "utf8"
img_url = re.findall('<img src="(.*?)" alt="(.*?)"', response2.text)[0]
directory = 'Wallpapers'
if not os.path.exists(directory):
os.makedirs(directory)
file_name = f'{directory}/{img_url[1]}.jpg'
with open(file_name, 'wb') as f:
response3 = requests.get(img_url[0], stream=True)
for chunk in response3.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
print(f'{file_name} downloaded!')
根据刚才一个易友分享的例子增加了一个下载保存的功能 其中Wallpapers文件夹是创建的下载的图片也在里面
|