#12 入门级js(0难度)- 猿人学 (yuanrenxue.com)
import base64
import requests
# 12题
def getM(page):
res = base64.b64encode(s = ('yuanrenxue' + str(page)).encode("utf8"))
return str(res)[2:-1]
def spider():
v = 0
for page in range(1,6):
m = getM(page)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36 Edg/92.0.902.55',
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,"
"application/signed-exchange;v=b3;q=0.9",
}
cookies = {
"sessionid":"", # 传入自己的sessionid
}
data = {
"page": page,
"m":m,
}
if page>3:
headers['User-Agent'] = 'yuanrenxue.project'
url = "http://match.yuanrenxue.com/api/match/12"
res = requests.get(url=url,headers=headers,params = data,cookies = cookies)
for data in res.json()['data']:
v += data['value']
print(v)
spider()