效果不错,我测试时会报路径错误和https错误,小改了下。
[Python] 纯文本查看 复制代码 # -*- coding: utf-8 -*-
import re
import requests
import os
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
url = "https://mp.weixin.qq.com/s/E0TTnkG0-kWetdf49edh9g"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/124.0.0.0 Safari/537.36"
}
response = requests.get(url=url, headers=headers).text
rule = re.compile('data-src="([^"]+)"').findall(response)
i = 1
img_path = "E:/壁纸"
if not os.path.exists(img_path):
os.makedirs(img_path)
for line in rule:
# 过滤掉非链接的数据
if line.startswith(("https", "http")):
images_data = requests.get(url=line, headers=headers).content
with open(f"{img_path}/{str(i)}.jpg", "wb") as f:
f.write(images_data)
print("正在下载第 " + str(i) + " 张图片")
i += 1
print("壁纸全部下载至【" + img_path + "】文件夹下, 请注意查看!")
|