本文主要是介绍python爬虫-AES.CBS加密案例(mmz批量爬取),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
下载mmz本页数据
批量下载请看主页!!!
代码:
import requests
from Crypto.Cipher import AES
import base64cookies = {'PHPSESSID': '48nu182kdlsmgfo2g7hl6eufsa','Hm_lvt_6cd598ca665714ffcd8aca3aafc5e0dc': '1710568549','SECKEY_ABVK': 'FUnr+pnCS/p1Ou/WiS6a82jLBmKcwlQfvALD/bEpSYS0EV42eXkFNYpCmcekNiiKvyrlcEHfDw6QLw7GSqcv/w%3D%3D','Hm_lpvt_6cd598ca665714ffcd8aca3aafc5e0dc': '1710568575','BMAP_SECKEY': 'FUnr-pnCS_p1Ou_WiS6a82jLBmKcwlQfvALD_bEpSYRjgInAaoK-vELl57QFAxX-y1kv64ZfrWIegR6xAqZk5YPrHMNgpor4__VOFQ2YBt9ZLJyD0Ru3kQ8TLNDX9tgT2rE6la_DNO7NooPoKY8lg-7nkrw7RqULcxikq6qpjt72ToZ7LhtjeWs5kU5TcRy2ruVzAKFKBpjmyUlPmKeBwJM_HQkgSUF_-wJjonbLE8U',
}headers = {'Accept': '*/*','Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6','Connection': 'keep-alive','Content-Type': 'application/json; charset=UTF-8',# 'Cookie': 'PHPSESSID=48nu182kdlsmgfo2g7hl6eufsa; Hm_lvt_6cd598ca665714ffcd8aca3aafc5e0dc=1710568549; SECKEY_ABVK=FUnr+pnCS/p1Ou/WiS6a82jLBmKcwlQfvALD/bEpSYS0EV42eXkFNYpCmcekNiiKvyrlcEHfDw6QLw7GSqcv/w%3D%3D; Hm_lpvt_6cd598ca665714ffcd8aca3aafc5e0dc=1710568575; BMAP_SECKEY=FUnr-pnCS_p1Ou_WiS6a82jLBmKcwlQfvALD_bEpSYRjgInAaoK-vELl57QFAxX-y1kv64ZfrWIegR6xAqZk5YPrHMNgpor4__VOFQ2YBt9ZLJyD0Ru3kQ8TLNDX9tgT2rE6la_DNO7NooPoKY8lg-7nkrw7RqULcxikq6qpjt72ToZ7LhtjeWs5kU5TcRy2ruVzAKFKBpjmyUlPmKeBwJM_HQkgSUF_-wJjonbLE8U','Origin': 'https://www.maomaozu.com','Referer': 'https://www.maomaozu.com/','Sec-Fetch-Dest': 'empty','Sec-Fetch-Mode': 'cors','Sec-Fetch-Site': 'same-origin','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0','sec-ch-ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Microsoft Edge";v="122"','sec-ch-ua-mobile': '?0','sec-ch-ua-platform': '"Windows"',
}# 参数加密
data = 'i1gpLEJyKvluv3sQVGr/h24MVjun9ZmA85MeQbGkMN/IIv+h8/9XooiKQN3pMc7C'response = requests.post('https://www.maomaozu.com/index/build.json', cookies=cookies, headers=headers, data=data)
res = response.text
# print(response.text)# 解密 b64
# print(base64.b64decode(res))
b64decode = base64.b64decode(res)# 解析mmz网站js拿到kv,服务器向浏览器传送数据的解密kv
key = '0a1fea31626b3b55'.encode()
vi = key
cry = AES.new(key, AES.MODE_CBC, vi)# print(cry.decrypt(b64decode).decode())
mmz_text = cry.decrypt(b64decode).decode()
print(mmz_text)
代码思维流程:
1、按照基础爬虫的思路,拿到目标网址进行模仿请求服务器并拿到数据
2、找到对应网页链接时,负载(请求)、响应都做了加密处理
3、先对响应的加密数据做解密处理,就可以获取到本页的数据
1)浏览器和服务器之前的传输是通过一系列的js代码进行的所以要在源码中找到解密的kv
2)搜索方法:搜索key、搜索路径、搜索"方法(函数)"、拦截器
3)使用搜索"方法(函数)"
4)在搜索到的位置上打断点,再刷新浏览器看停在那个位置
5)逐步分析,找到解密的方法即可找到key和iv
4、找到后即可完成解密操作获取到数据
这篇关于python爬虫-AES.CBS加密案例(mmz批量爬取)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!