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)