import requests
from collections import Counter
# 使用 Fiddler抓包工具获取请求头顺序
headers = {
'Host': 'match.yuanrenxue.cn',
'Connection': 'keep-alive',
'Pragma': 'no-cache',
'Content-Length': '0',
'Cache-Control': 'no-cache',
'sec-ch-ua': '"Chromium";v="128", "Not;A=Brand";v="24", "Google Chrome";v="128"',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'X-Requested-With': 'XMLHttpRequest',
'sec-ch-ua-mobile': '?0',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
'sec-ch-ua-platform': '"Windows"',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Dest': 'empty',
'Referer': 'https://match.yuanrenxue.cn/match/3',
'Accept-Encoding': 'gzip, deflate, br, zstd',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Cookie': 'Hm_lvt_9bcbda9cbf86757998a2339a0437208e=1725092157,1725260058,1725328822,1725602951; HMACCOUNT=AD4B37429D450BF5; Hm_lvt_c99546cf032aaa5a679230de9a95c7db=1725092151,1725260059,1725328822,1725602951; qpfccr=true; no-alert3=true; tk=-8776881338397552859; sessionid=snadh4xp4ir283s1loa3gc8cyo1mlw27; Hm_lpvt_9bcbda9cbf86757998a2339a0437208e=1725602968; Hm_lpvt_c99546cf032aaa5a679230de9a95c7db=1725602982'
}
list = []
for page in range(1, 6):
# 使用session固定请求头
session = requests.Session()
session.headers = headers
res = session.post('https://match.yuanrenxue.cn/jssm')
print(res.cookies)
url = f'https://match.yuanrenxue.cn/api/match/3?page={page}'
response = session.get(url)
# print(response.status_code)
# print(response.text)
data = response.json()['data']
for item in data:
value = item['value']
list.append(value)
# 统计列表的各元素出现的次数
word_count = Counter(list)
print(word_count)
# 输出出现次数最多的元素
most_common_words = word_count.most_common(1)
print(most_common_words)
标签:cn,session,yuanrenxue,Hm,print,match,猿人
From: https://www.cnblogs.com/lsixu/p/18400401