-
Notifications
You must be signed in to change notification settings - Fork 0
/
cuit.py
154 lines (145 loc) · 5.11 KB
/
cuit.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
147
148
149
150
151
152
153
154
import requests
import re
import json
import execjs
class FC(object):
cookie = ""
ocrServer = ""
def __init__(self, cookie, ocrServer):
self.cookie = cookie
self.ocrServer = ocrServer
pass
def fuckCourse(self, profiledId, lessonId):
try:
body = {
"optype": "true",
"operator0": lessonId + ":true:0",
"lesson0": lessonId,
"schLessonGroup_" + lessonId:"undefined"
}
req = requests.post("http://jwgl.cuit.edu.cn/eams/stdElectCourse!batchOperator.action?profileId=" + profiledId,
headers={
"cookie": self.cookie,
"X-Requested-With": "XMLHttpRequest",
"Referer" : "http://jwgl.cuit.edu.cn/eams/stdElectCourse!batchOperator.action?profileId=" + profiledId,
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.0 Safari/537.36 Edg/84.0.521.0"
}, data=body, timeout=5, allow_redirects=False)
req.encoding = 'utf-8'
html = req.text
ret = re.search(r"margin:auto;\">\n\t\t\t\t(.*)<\/br>", html)
if ret == None:
print("cookie过期")
exit(-1)
pass
print(ret.group(1))
req.close()
if '成功' in ret.group(1):
print('get')
return True
except Exception as err:
print("出错")
print(err)
return False
pass
pass
def getPic(self):
url="http://jwgl.cuit.edu.cn/eams/captcha/image.action"
headers = {
'cookie': self.cookie
}
while True:
try:
picReq=requests.get(url=url, headers=headers, timeout=5)
break
except Exception as err:
continue
# print(picReq.content)
return picReq.content
pass
def postOCRPic(self, pic):
url = self.ocrServer
files = {'captcha': pic}
data = {
'enctype':'multipart/form-data',
'name':'captcha'
}
ocrReq=requests.post(url=url, data=data, files=files)
# print(ocrReq.content)
return json.loads(ocrReq.content)
pass
'''
'''
def checkCaptcha(self, captcha, profiledId):
url="http://jwgl.cuit.edu.cn/eams/stdElectCourse!defaultPage.action"
headers = {
'cookie': self.cookie
}
data = {
'captcha_response': captcha,
'electionProfile.id': profiledId
}
while True:
try:
checkReq = requests.post(url=url, headers=headers, data=data, allow_redirects=False, timeout=5)
break
except Exception as err:
continue
# print(checkReq.text)
# 未登录与验证码错误都是302,但Location去向不同
if checkReq.status_code == 200 :
return True
elif 'sso' in checkReq.headers['Location']:
# 转到统一登录中心
print('cookie失效!!!')
exit(1)
return False
pass
def isAvailable(self, captcha, profiledId):
url="http://jwgl.cuit.edu.cn/eams/stdElectCourse!defaultPage.action"
headers = {
'cookie': self.cookie
}
data = {
'captcha_response': captcha,
'electionProfile.id': profiledId
}
while True:
try:
checkReq = requests.post(url=url, headers=headers, data=data, allow_redirects=False, timeout=5)
break
except Exception as err:
continue
# print(checkReq.text)
# 未登录与验证码错误都是302,但Location去向不同
if checkReq.status_code == 200 :
return '不在选课时间内' not in checkReq.text
elif 'sso' in checkReq.headers['Location']:
# 转到统一登录中心
print('cookie失效!!!')
self.cookie = input("请输入新的cookie:")
False
return False
pass
def courseName2Id(self, profileId, courseName):
url="http://jwgl.cuit.edu.cn/eams/stdElectCourse!data.action?profileId=" + str(profileId)
headers = {
'cookie': self.cookie
}
while True:
try:
courseListReq = requests.get(url=url, headers=headers, allow_redirects=False, timeout=5)
break
except Exception as err:
continue
courseList = courseListReq.text
# with open('test/html/courseList.html',encoding='utf-8') as f:
# courseList = f.read()
# print(courseList)
jsData = execjs.compile(courseList)
lessonJSONs = jsData.eval('lessonJSONs')
# print(lessonJSONs)
for lesson in lessonJSONs:
if courseName in lesson['name']:
return lesson['id']
return None
pass