猿人学题库第七题——请求规律检测——采坑式学习

1. 首先先抓包能看到抓取第一页,第二页,第三页,第四页的时候每次 challenge7 请求前面都有个 cityjson 请求,这里后台有个请求规律判断,必须请求 cityjson之后在请求challenge7才能获取数据。

2.发起 cityjson 后会返回 var returnCitySN = {"cip": "ip地址", "timestamp": "1744011432"}; 值,估计后端 会给 ip 做一个标识 和一个时间戳

3.所以逻辑就是先执行 cityjson 请求在执行 challenge7 ,就能返回正常数据了。接下来话不多说直接撸代码。

4.完整代码:

python 复制代码
import requests



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',
    'x-requested-with': 'XMLHttpRequest',
}
vuels=0
for i in range(1,101):
    data = {
        'page': i,
    }
    requests.post('https://www.python-spider.com/cityjson',  headers=headers)
    response = requests.post('https://www.python-spider.com/api/challenge7',  headers=headers, data=data)
    print(response.json())
    decrypted_numbers = [int(s['value']) for s in response.json()['data']]
    vuels+=sum(decrypted_numbers)
print(vuels)
相关推荐
看海天一色听风起雨落1 天前
Python学习之装饰器
开发语言·python·学习
speop1 天前
llm的一点学习笔记
笔记·学习
非凡ghost1 天前
FxSound:提升音频体验,让音乐更动听
前端·学习·音视频·生活·软件需求
ue星空1 天前
月2期学习笔记
学习·游戏·ue5
萧邀人1 天前
第二课、熟悉Cocos Creator 编辑器界面
学习
m0_571372821 天前
嵌入式ARM架构学习2——汇编
arm开发·学习
AlexMercer10121 天前
[前端]1.html基础
前端·笔记·学习·html
一川月白7091 天前
51单片机---硬件学习(跑马灯、数码管、外部中断、按键、蜂鸣器)
单片机·学习·51单片机·外部中断·蜂鸣器·数码管·跑马灯
励志不掉头发的内向程序员1 天前
STL库——二叉搜索树
开发语言·c++·学习
ホロHoro1 天前
学习笔记:MYSQL(4)
笔记·学习·mysql