forked from Kevin-100717/zhixue_api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetData.py
More file actions
72 lines (72 loc) · 3.44 KB
/
Copy pathgetData.py
File metadata and controls
72 lines (72 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from loguru import logger
from getUser import ZhixueUserLogin
import requests,json
class ZhixueWeb:
def __init__(self):
self.account = ZhixueUserLogin("cookies.json")
self.headers = {
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 Edg/148.0.0.0",
"Referer":"https://www.zhixue.com/htm-vessel/",
"Host":"www.zhixue.com"
}
def init(self):
self.userToken = self.get_token()
self.headers2 = {
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36 Edg/148.0.0.0",
"Referer":"https://www.zhixue.com",
"token":self.userToken,
"xtoken":self.userToken
}
logger.info(self.userToken)
self.years = self.get_year()
def get_token(self):
url = "https://www.zhixue.com/container/app/token/getToken"
h = self.headers
#h["Cookies"] = self.account.cookie_to_str(self.account.login_cookie)
print(self.account.cookies)
result = requests.get(url,headers=h,cookies=self.account.cookies).json()
logger.info(json.dumps(result))
return result["result"]
def get_year(self):
url = "https://ali-bg.zhixue.com/zhixuebao/base/common/academicYear"
logger.debug(self.headers2)
result = requests.get(url,headers=self.headers2,cookies=self.account.cookies)
logger.info(result.text)
return result.json()["result"]
def get_exam(self,yi):
end = False
datas = []
url = "https://ali-bg.zhixue.com/zhixuebao/report/exam/getUserExamList?pageIndex=1&pageSize=10&startSchoolYear="+self.years[yi]["beginTime"]\
+"&endSchoolYear="+self.years[yi]["endTime"]
while not end:
logger.debug(self.headers2)
result = requests.get(url,headers=self.headers2,cookies=self.account.cookies)
logger.info(result.text)
d = result.json()
for da in d["result"]["examList"]:
datas.append(da)
if not d["result"]["hasNextPage"]:
end = True
else:
url = "https://ali-bg.zhixue.com/zhixuebao/report/exam/getUserExamList?pageIndex="+str(d["result"]["pagination"]["pageIndex"])+\
"&pageSize="+str(d["result"]["pagination"]["pageSize"])+"&startSchoolYear="+self.years[yi]["beginTime"]\
+"&endSchoolYear="+self.years[yi]["endTime"]
return datas
def get_detail(self,eid):
url = "https://ali-bg.zhixue.com/zhixuebao/report/exam/getReportMain?examId="+eid
logger.debug(self.headers2)
result = requests.get(url,headers=self.headers2,cookies=self.account.cookies)
logger.info(result.text)
return result.json()
def get_answer(self,eid,pid,yi,sjc):
u = "https://www.zhixue.com/zhixuebao/zhixuebao/transcript/analysis/main/?subjectCode="+sjc\
+"&classId=null&paperId="+pid\
+"&examId="+eid\
+"&token="+self.userToken+"&startSchoolYear="+self.years[yi]["beginTime"]\
+"&endSchoolYear="+self.years[yi]["endTime"]
html = requests.get(u,headers=self.headers,cookies=self.account.cookies)
html = html.text
res = html.split("var hisQueParseDetail = ")[1].split("];")[0]+']'
res = json.loads(res)
logger.info(res)
return res