-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathxjtu.py
More file actions
executable file
·312 lines (291 loc) · 11.2 KB
/
xjtu.py
File metadata and controls
executable file
·312 lines (291 loc) · 11.2 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
__author__ = 'Suarezlin'
import requests
import re
from bs4 import BeautifulSoup
import prettytable
import pyquery
import time
class DEAN:
def __init__(self):
self.login = 'https://cas.xjtu.edu.cn/login'
self.posturl = 'http://ssfw.xjtu.edu.cn/index.portal'
self.classurl = 'http://ssfw.xjtu.edu.cn/index.portal?.pn=p1142_p1145_p1542'
self.gradeurl = 'http://ssfw.xjtu.edu.cn/index.portal?.pn=p1142_p1144_p1156'
self.pingjiaourl = 'http://ssfw.xjtu.edu.cn/index.portal?.pn=p1142_p1182_p1183'
self.header = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
'Host': 'ssfw.xjtu.edu.cn',
'Referer': 'http://ssfw.xjtu.edu.cn/',
'Connection': 'keep-alive',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate, sdch',
'Accept-Language': 'zh-CN,zh;q=0.8',
'Cache-Control': 'max-age=0',
'Upgrade-Insecure-Requests': '1'
}
self.session = requests.session()
def getLt(self):
request = self.session.get(self.posturl)
request = request.text
str = 'name="lt" value="(.*?)"'
pattern = re.compile(str, re.S)
lt = re.findall(pattern, request)
return lt[0]
def logIn(self):
print('请输入NetID:')
self.username = input()
print('请输入密码:')
self.password = input()
print('登录中请稍候')
str = '登录'
str = str.encode('utf-8')
postdata = {
'username': self.username,
'password': self.password,
'code': '',
'lt': self.getLt(),
'execution': 'e1s1',
'_eventId': 'submit',
'submit': str
}
self.session.post(self.login, postdata)
time.sleep(0.1)
r = self.session.get(self.posturl)
soup = BeautifulSoup(r.text, 'html.parser').find('meta').get('content')[6:]
time.sleep(0.1)
self.session.get(soup)
# 登录完成
def ins(self, a):
if len(a) < 4:
number = []
for it in a:
search = '~'
start = 0
index = it.find(search, start)
if index > 0:
number.append(it[index - 1])
if '1' not in number:
a.insert(0, '')
if '3' not in number:
a.insert(1, '')
if '5' not in number:
a.insert(2, '')
if '7' not in number:
a.insert(3, '')
def getGI(self):
s = self.session.get(self.posturl)
text = s.text
pattern = re.compile(
'学号.*?"span_unedit">(.*?)</span>.*?姓名.*?"span_unedit">(.*?)</span>.*?性别.*?"span_unedit">(.*?)</span>.*?出生日期.*?"span_unedit">(.*?)</span>.*?民族.*?"span_unedit">(.*?)</span>.*?班级名称.*?"span_unedit">(.*?)</span>.*?学院.*?"span_unedit">(.*?)</span>',
re.S)
item = re.findall(pattern, text)
item = item[0]
x = prettytable.PrettyTable(["学号", "2150400330"])
x.align["学号"] = "l"
x.padding_width = 1
x.add_row(["姓名", item[1]])
x.add_row(["性别", item[2]])
x.add_row(["出生日期", item[3]])
x.add_row(["民族", item[4]])
x.add_row(["班级", item[5]])
x.add_row(["学院", item[6]])
print(x)
def getSchedule(self):
text = self.session.get(self.classurl).text
pattern = re.compile('<div class="fcSpanDiv"></div></div>(.*?)</td>', re.S)
items = re.findall(pattern, text)
p = re.compile(' (.*?)<br>(.*?)<br>(.*?) (.*?) (.*?)<br>(.*?)\n')
schedual = []
for it in items:
a = []
t = re.findall(p, it)
for it in t[0]:
a.append(it)
schedual.append(a)
table = []
for it in schedual:
if '单' in it[2]:
it[2]=it[2].replace('(单)', '')
it[2] += '|单'
elif '双' in it[2]:
it[2]=it[2].replace('(双)', '')
it[2] += '|双'
it[2] = '第' + it[2]
it[3] = it[3] + it[4]
del it[4]
it[4] = it[4][1:-2]
table.append(it)
return table
def getClassTable(self):
r = self.session.get(self.classurl)
pattern = re.compile('class="fcSpanDiv"></div></div>(.*?)</td><td colspan=1 rowspan=".*?">', re.S)
trs = re.findall(pattern, r.text)
replaceBR = re.compile('<br>')
replaceNBSP = re.compile(' ')
text = []
classinfo = []
for it in trs:
text.append(re.sub(replaceBR, "\n", it))
for it in text:
classinfo.append(re.sub(replaceNBSP, " ", it))
i = 0
mon = []
tue = []
wen = []
thr = []
fry = []
for it in classinfo:
if '周一' in it:
mon.append(it)
elif '周二' in it:
tue.append(it)
elif '周三' in it:
wen.append(it)
elif '周四' in it:
thr.append(it)
elif '周五' in it:
fry.append(it)
self.ins(mon)
self.ins(tue)
self.ins(wen)
self.ins(thr)
self.ins(fry)
x = prettytable.PrettyTable(["周一", "周二", "周三", "周四", "周五"])
x.align["周一"] = "l"
x.padding_width = 1
x.add_row([mon[0], tue[0], wen[0], thr[0], fry[0]])
x.add_row([mon[1], tue[1], wen[1], thr[1], fry[1]])
x.add_row([mon[2], tue[2], wen[2], thr[2], fry[2]])
x.add_row([mon[3], tue[3], wen[3], thr[3], fry[3]])
print(x)
def getGrade(self):
r = self.session.get(self.gradeurl)
text = r.text
b = pyquery.PyQuery(text)
a = b("[href=####]")
print(a)
# print(text)
pattern = re.compile(
'<td class="">(.*?)</td>.*?<td class="">(.*?)</td>.*?<td class="">(.*?)</td>.*?<td class="">(.*?)</td>.*?<td class="">(.*?)</td>.*?<td class="">.*?">(.*?)</a>.*?<td class="">(.*?)</td>.*?<td class="">(.*?)</td>.*?<td class="">(.*?)</td>.*?<td class="">(.*?)</td>',
re.S)
s = re.findall(pattern, text)
x = prettytable.PrettyTable(["学年学期", "课程代码", "课程名称", "课程类别", "考试性质", "成绩", "学分", "特殊原因", "修读性质", "是否生效"])
x.align["学年学期"] = "l"
x.padding_width = 1
a = []
for it in s:
ss = list(it)
aa = []
for ch in ss:
ch = ch.lstrip()
ch = ch.rstrip()
aa.append(ch)
a.append(aa)
for it in a:
x.add_row(it)
print(x)
def pinjiao(self):
r = self.session.get(self.pingjiaourl)
pattern = re.compile('href="(.*?)">评教</a>', re.S)
content = re.findall(pattern, r.text)
data = {
'wid_pgjxb': '3BB97DF9DB840329E05075CA55013B4D',
'wid_pgyj': '',
'type': '2',
'sfytj': 'true',
'pjType': '4',
'wid_pjzts': {'3B9946A7BB7FEE45E05075CA550179D4_0', '3B9946A7BBB5EE45E05075CA550179D4_0',
'3BB97DF9D6B50329E05075CA55013B4D_0', '3BB97DF9D6C70329E05075CA55013B4D_0',
'3BB97DF9D85D0329E05075CA55013B4D_0', '3BB97DF9DB480329E05075CA55013B4D_0',
'BB97DF9DB820329E05075CA55013B4D_0', '3BB97DF9DB840329E05075CA55013B4D_0',
'3BB97DF9DC200329E05075CA55013B4D_2', '3BB97DF9DF200329E05075CA55013B4D_0', },
'status': '0',
'ztpj': '很好',
'sfmxpj': 'false',
'zbbm': 'PJYJZB0581_PJEJZB0602',
'wid_PJYJZB0581_PJEJZB0602': '',
'qz_PJYJZB0581_PJEJZB0602': '12.5',
'pfdj_PJYJZB0581_PJEJZB0602': 'PJDJ0593',
'zbbm': 'PJYJZB0581_PJEJZB0607',
'wid_PJYJZB0581_PJEJZB0607': '',
'qz_PJYJZB0581_PJEJZB0607': '0',
'pfdj_PJYJZB0581_PJEJZB0607': 'PJDJ0593',
'zbbm': 'PJYJZB0581_PJEJZB0584',
'wid_PJYJZB0581_PJEJZB0584': '',
'qz_PJYJZB0581_PJEJZB0584': '12.5',
'pfdj_PJYJZB0581_PJEJZB0584': 'PJDJ0594',
'zbbm': 'PJYJZB0581_PJEJZB0603',
'wid_PJYJZB0581_PJEJZB0603': '',
'qz_PJYJZB0581_PJEJZB0603': '20',
'pfdj_PJYJZB0581_PJEJZB0603': 'PJDJ0593',
'zbbm': 'PJYJZB0581_PJEJZB0604',
'wid_PJYJZB0581_PJEJZB0604': '',
'qz_PJYJZB0581_PJEJZB0604': '12.5',
'pfdj_PJYJZB0581_PJEJZB0604': 'PJDJ0593',
'zbbm': 'PJYJZB0581_PJEJZB0585',
'wid_PJYJZB0581_PJEJZB0585': '',
'qz_PJYJZB0581_PJEJZB0585': '12.5',
'pfdj_PJYJZB0581_PJEJZB0585': 'PJDJ0593',
'zbbm': 'PJYJZB0581_PJEJZB0586',
'wid_PJYJZB0581_PJEJZB0586': '',
'qz_PJYJZB0581_PJEJZB0586': '20',
'pfdj_PJYJZB0581_PJEJZB0586': 'PJDJ0593',
'zbbm': 'PJYJZB0581_PJEJZB0587',
'wid_PJYJZB0581_PJEJZB0587': '',
'qz_PJYJZB0581_PJEJZB0587': '10',
'pfdj_PJYJZB0581_PJEJZB0587': 'PJDJ0592',
'zbbm': 'PJYJZB0581_PJEJZB0596',
'wid_PJYJZB0581_PJEJZB0596': '',
'qz_PJYJZB0581_PJEJZB0596': '0',
'pfdj_PJYJZB0581_PJEJZB0596': 'PJDJ0593',
'zbbm': 'PJYJZB0581_PJEJZB0606',
'wid_PJYJZB0581_PJEJZB0606': '',
'qz_PJYJZB0581_PJEJZB0606': '0',
'pfdj_PJYJZB0581_PJEJZB0606': 'PJDJ0593',
'pgyj': '很好',
'actionType': '2'
}
for it in content:
url = 'http://ssfw.xjtu.edu.cn/index.portal' + it
s = self.session.post(url, headers=data)
def __main__():
def menu():
print('=====欢迎=====')
print('1. 查看基本信息')
print('2. 查课表')
print('3. 查成绩')
print("4. 退出")
print('5. 一键评教')
print("=================")
print(">>>")
s = input()
return s
def case1():
dean.getGI()
def case2():
dean.getClassTable()
def case3():
dean.getGrade()
def case4():
exit(0)
def case5():
dean.pinjiao()
def f(o):
switch.get(o)()
dean = DEAN()
dean.logIn()
print('登录成功')
switch = {'1': case1, '2': case2, '3': case3, '4': case4, '5': case5}
while True:
try:
f(menu())
except:
print("登录出现问题,请稍后再试")
print("输入任意数字继续")
input()
if __name__ == "__main__":
dean = DEAN()
dean.logIn()
print('登录成功')
dean.getSchedule()
# __main__()