前言
嗨喽~大家好呀,这里是魔王呐 ❤ ~!
python更多源码/资料/解答/教程等 点击此处跳转文末名片免费获取
开发环境:
-
python 3.8 运行代码
-
pycharm 2021.2 辅助敲代码
-
requests 第三方模块
-
Fiddler 汉化版 抓包的工具
配置Fiddler环境
先打开Fiddler,选择工具,再选选项
在选项窗口里点击HTTPS,把勾选框都勾选上
在选项窗口里点击链接,把勾选框都勾选上,然后点击确定即可
我们还需要在客户端把网络代理开启
-
地址:127.0.0.1
-
端口:8888
代码展示
导入模块
import requests
import re
proxies = {
'http': 'http://127.0.0.1:9000',
'https': 'http://127.0.0.1:9000'
}
模拟伪装
'''
学习中遇到问题没人解答?小编创建了一个Python学习交流QQ群:926207505
寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
'''
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x63090621) XWEB/8379 Flue',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'cache-control': 'max-age=0',
'upgrade-insecure-requests': '1',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'navigate',
'sec-fetch-user': '?1',
'sec-fetch-dest': 'document',
'referer': 'https://mp.weixin.qq.com/s?__biz=MzI5NTY0MzYxOQ==&mid=2247509410&idx=1&sn=b5cb234e5969ca7ca6a7f1ced129389f&chksm=1f4f38a8ec6d848a63f6ec27345def1db18cffacf708b53c9e78c59a98a7066b5a0c67011ee3&scene=27&key=33032cfbebd259b04a56c30a21a0429cd6ff501f34f2a1cceedf5e2ed5ec4af79f0c5415ab9318c57e12a59777e6a30ea58c4e086d70c6cfbc34c44f41c3f9dcc2e57a205fdf36256416edd76909a42bf1ae47f6a742522547e4afd5f8bdc18a5e236a7fbff86bdfa5abd1dfa76bb6db0bc26d075c749314c7b4cf68019d8554&ascene=7&uin=MjQwODIxNTMyMw%3D%3D&devicetype=Windows+10+x64&version=63090621&lang=zh_CN&countrycode=CN&exportkey=n_ChQIAhIQVUb9ZjTYN%2F67OOozrKhZAhLRAQIE97dBBAEAAAAAAB2BGcaSZ4EAAAAOpnltbLcz9gKNyK89dVj0C0JI259tMWf9nJziaXLlr%2F972iVeulc1eUt7OEzTN1nQ4BL9bfUQk59hmh0G3LAmno9P8LvfjcZ87icz14EfQUj66RxUfv6YFZ8DWAFmpLNI6YotPFBFhiNu6BEhCKDM4XNYgev%2FOmjfsXOJgFfVpmQ3BXEvlIk50P3ITLHzxWg3UXSMMiqzTVaQkV6a0yvkKTiD99qJId7gVZ0cUJDC5jFy3ZGAiZ7d5Cfg&acctmode=0&pass_ticket=qf8WjpxkGZ3We%2F11IN4L7zYyTkpgsaG3OGyuHpZU8YdDJzFdAXk5cfjTyrUkdKRy&wx_header=1',
'accept-language': 'zh-CN,zh',
'cookie': 'wxuin=2408215323',
'cookie': 'lang=zh_CN',
'cookie': 'rewardsn=',
'cookie': 'wxtokenkey=777',
'cookie': 'devicetype=Windows10x64',
'cookie': 'version=63090621',
'cookie': 'pass_ticket=qf8WjpxkGZ3We/11IN4L7zYyTkpgsaG3OGyuHpZU8YdDJzFdAXk5cfjTyrUkdKRy',
'cookie': 'appmsg_token=1232_LuoKrM66cSU9VHIVzGbO8XZPKeAfQOQLTALEUdpleRik3azzGX3sqi3v35fMlE7_HxjTHAkGSYUpfp_Z',
'cookie': 'wap_sid2=CJvmqfwIEooBeV9IRElIZkRwajNMQW9FUWpNV1hNakNaWF9ILTlwR0NtX21CS1NtaTBaZXdEeVBkYUh1aGR4WWp6ekxMczc1SVkyY0tUX2xvRTAwQkt4T0dDdkpKenNGOGNfMUtqajdzNFBuaUp3Mk1XbERWcXR0cEQ4MmNQUzJTTHdaRnBncl9CWENhNFNBQUF+MM3Kt6cGOA1AAQ==',
'if-modified-since': 'Tue, 29 Aug 2023 20:24:08 +0800',
}
请求链接
url = 'https://mp.weixin.qq.com/s?__biz=MzI5NTY0MzYxOQ==&mid=2247509410&idx=1&sn=b5cb234e5969ca7ca6a7f1ced129389f&chksm=1f4f38a8ec6d848a63f6ec27345def1db18cffacf708b53c9e78c59a98a7066b5a0c67011ee3&scene=27&key=33032cfbebd259b04a56c30a21a0429cd6ff501f34f2a1cceedf5e2ed5ec4af79f0c5415ab9318c57e12a59777e6a30ea58c4e086d70c6cfbc34c44f41c3f9dcc2e57a205fdf36256416edd76909a42bf1ae47f6a742522547e4afd5f8bdc18a5e236a7fbff86bdfa5abd1dfa76bb6db0bc26d075c749314c7b4cf68019d8554&ascene=7&uin=MjQwODIxNTMyMw==&devicetype=Windows%2010%20x64&version=63090621&lang=zh_CN&countrycode=CN&exportkey=n_ChQIAhIQVUb9ZjTYN/67OOozrKhZAhLRAQIE97dBBAEAAAAAAB2BGcaSZ4EAAAAOpnltbLcz9gKNyK89dVj0C0JI259tMWf9nJziaXLlr/972iVeulc1eUt7OEzTN1nQ4BL9bfUQk59hmh0G3LAmno9P8LvfjcZ87icz14EfQUj66RxUfv6YFZ8DWAFmpLNI6YotPFBFhiNu6BEhCKDM4XNYgev/OmjfsXOJgFfVpmQ3BXEvlIk50P3ITLHzxWg3UXSMMiqzTVaQkV6a0yvkKTiD99qJId7gVZ0cUJDC5jFy3ZGAiZ7d5Cfg&acctmode=0&pass_ticket=qf8WjpxkGZ3We/11IN4L7zYyTkpgsaG3OGyuHpZU8YdDJzFdAXk5cfjTyrUkdKRy&wx_header=1'
发送请求
verify=False: 忽略证书验证
response = requests.get(url=url, headers=headers, proxies=proxies, verify=False)
html_data = response.text
解析数据
<img.?data-src=".?"
所有的图片内容 在网页当中 都是 <img.?data-src=".?" 标签开头的
img_list = re.findall('<img.*?data-src="(.*?)"', html_data)
index = 0
保存数据
for img in img_list[:-1]:
img_data = requests.get(img, proxies=proxies, verify=False).content
open(f'img/{index}.jpg', mode='wb').write(img_data)
index += 1
尾语
最后感谢你观看我的文章呐~本次航班到这里就结束啦 🛬
希望本篇文章有对你带来帮助 🎉,有学习到一点知识~
躲起来的星星🍥也在努力发光,你也要努力加油(让我们一起努力叭)。