查看数据接口 https://match.yuanrenxue.cn/api/match/13
请求参数只携带了 page 页码
请求时需要携带 cookie yuanrenxue_cookie字段
在请求的时将 cookie 中对应的 yuanrenxue_cookie 字段删除
勾选事件监听断点中的脚本断点后刷新页面即可看到 cookie 生成的位置
这段代码是在 script 标签里的,可以用 正则匹配
使用 subprocess 输出 cookie 信息即可
对应 python 代码
import subprocess
import requests
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36"
}
cookies = {
"sessionid": "你的sessionId",
}
def get_yuanrenxue_cookie(js_code):
command = "node -e " + js_code + ';\n' + 'console.log(cookie)'
output = subprocess.check_output(command)
return output.strip().split('=')[1].split(';')[0]
def send_match13():
url = "https://match.yuanrenxue.cn/match/13"
response = requests.get(url, headers=headers, cookies=cookies)
js_code = re.findall("(cookie=.*?';path=/')", response.text)[0]
cookies['yuanrenxue_cookie'] = get_yuanrenxue_cookie(js_code)
完整的 python 代码
import re
import subprocess
import requests
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36"
}
cookies = {
"sessionid": "你的SessionId",
}
def get_yuanrenxue_cookie(js_code):
command = "node -e " + js_code + ';\n' + 'console.log(cookie)'
output = subprocess.check_output(command)
return output.strip().split('=')[1].split(';')[0]
def send_match13():
url = "https://match.yuanrenxue.cn/match/13"
response = requests.get(url, headers=headers, cookies=cookies)
js_code = re.findall("(cookie=.*?';path=/')", response.text)[0]
cookies['yuanrenxue_cookie'] = get_yuanrenxue_cookie(js_code)
def send_data(page_):
url = "https://match.yuanrenxue.cn/api/match/13"
params = {
"page": f"{page_}"
}
response = requests.get(url, headers=headers, cookies=cookies, params=params)
return response.json()['data']
if __name__ == '__main__':
send_match13()
nums = 0
for page in range(1, 6):
nums_list = send_data(page)
for num in nums_list:
nums += num['value']
print('page: ', page, 'nums: ', nums)