import execjs
import requests
with open('yuanrenxue.js', 'r', encoding='utf-8') as f:
jscode = f.read()
ctx = execjs.compile(jscode)
headers = {
"referer": "https://match.yuanrenxue.cn/match/6",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
"x-requested-with": "XMLHttpRequest"
}
cookies = {
"sessionid": "4wz0jj4vnvy0xy9i2w8by2nq7rc6e4oa"
}
url = "https://match.yuanrenxue.cn/api/match/6"
sum = 0
for page in range(1, 6):
data = ctx.call('mEncrypt', page)
params = {
"page": str(page),
"m": data['m'],
"q": f"{page}-{data['t']}|"
}
response = requests.get(url, headers=headers, cookies=cookies, params=params)
if response.status_code == 200:
items = response.json()['data']
print(items)
for item in items:
sum += item['value'] * 24
print('采集全部5页的彩票数据,计算全部中奖的总金额(包含一、二、三等奖): ', sum)