-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
146 lines (125 loc) · 5.46 KB
/
api.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import requests
import requests.utils
class PK1024Api(object):
"""1024比赛"""
def __init__(self):
self.sess = requests.session()
def login_first(self, uid, password):
"""
登录首页(用不着)
"""
headers = {
'Host': '1024.baby-bus.com',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 '
'(KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin': 'http://1024.baby-bus.com',
'Referer': 'http://1024.baby-bus.com/index.php/Index/Index/index.html',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,da;q=0.7',
}
url = 'http://1024.baby-bus.com/index.php/Index/Index/doLogin.html'
data = {
'id': uid,
'password': password,
}
resp = self.sess.post(url=url, headers=headers, data=data).json()
return resp
def login_exam(self, uid, email):
"""
登录考试
"""
headers = {
'Host': '1024aq.baby-bus.com',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/86.0.4240.111 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin': 'http://1024aq.baby-bus.com',
'Referer': f'http://1024aq.baby-bus.com/index.php/Home/Index/index.html?id={uid}&email={email}',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,da;q=0.7',
}
url = 'http://1024aq.baby-bus.com/index.php/Home/User/login.html'
data = {
'id': uid,
'email': email,
}
resp = self.sess.post(url=url, headers=headers, data=data).json()
return resp
def post_user_mes(self):
"""
提交用户信息
:return:
"""
headers = {
'Host': '1024aq.baby-bus.com',
'Cache-Control': 'max-age=0',
'Upgrade-Insecure-Requests': '1',
'Origin': 'http://1024aq.baby-bus.com',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/86.0.4240.111 Safari/537.36',
'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',
'Referer': 'http://1024aq.baby-bus.com/index.php/Home/Index/user_mes.html',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,da;q=0.7',
}
# 要把这个信息改为自己的
data = {
"Name": "匿名",
"Sex": "1",
"birthday": "2000-01-01",
"Polity": "团员",
"AreaCategory_txt": "福建省",
"AreaCategory": "3400",
"Tel": "",
"University": "中央广播电视大学",
"Professional": "计算机科学与技术",
"IndustryCategory_txt": "",
"IndustryCategory": "9",
"Jobs": "",
"Department": "",
# 这个ID应该是固定不变的
"FK_BeisenUser_ID": "114895095",
}
url = 'http://1024aq.baby-bus.com/index.php/Home/Index/user_mes_submit'
resp = self.sess.post(url=url, headers=headers, data=data)
return resp
def pre_read(self):
"""
这个用不到
:return:
"""
headers = {
'Host': '1024aq.baby-bus.com',
'Cache-Control': 'max-age=0',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/86.0.4240.111 Safari/537.36',
'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',
'Referer': 'http://1024aq.baby-bus.com/index.php/Home/Index/user_mes.html',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,da;q=0.7',
}
url = 'http://1024aq.baby-bus.com/index.php/Home/Index/pre_read.html'
resp = self.sess.get(url=url, headers=headers)
return resp
def get_formal2(self):
"""
获取答题页面
"""
headers = {
'Host': '1024aq.baby-bus.com',
'Pragma': 'no-cache',
'Cache-Control': 'no-cache',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/86.0.4240.111 Safari/537.36',
'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',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,da;q=0.7',
}
url = 'http://1024aq.baby-bus.com/index.php/Home/Index/formal2'
resp = self.sess.get(url=url, headers=headers)
return resp