forked from sdogsq/UCAS-Course-Evaluate-20Spring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutoEvaluate.py
151 lines (133 loc) · 4.68 KB
/
AutoEvaluate.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
#!/usr/bin/env python
# coding: utf-8
import requests
import re
import time
import json
from bs4 import BeautifulSoup
onestop_data = {'username': 'Your user name', # 填入用户名
'password': 'Your password', # 填入密码
'remember': 'checked'}
# ------------------- login onestop -------------------------
onestop_link = "http://onestop.ucas.ac.cn/Ajax/Login/0"
headers = { # 请求头信息
'X-Requested-With': 'XMLHttpRequest'
}
o = requests.Session()
Onestop_Login = o.post(url = onestop_link, data = onestop_data, headers = headers, verify=False, timeout=10)
res = json.loads(Onestop_Login.text)
if (res['f'] == False): # check login status
raise Exception(res['msg'])
else:
print("ONESTOP LOGIN SUCCESS")
# -------------------------------------------------------
# ------------------- login sep -------------------------
s = requests.Session()
Sep_Login = s.get(url=res['msg'],verify=False,timeout=10) # login
sl = BeautifulSoup(Sep_Login.text, 'lxml')
if (sl.find('a',title='退出系统') == None): # check login status
raise Exception("Sep Login Error")
else:
print("SEP LOGIN SUCCESS")
# -------------------------------------------------------
# ------------------- login jwxk -----------------------
jwxk = s.get('http://sep.ucas.ac.cn/portal/site/226/821')
jwxk = BeautifulSoup(jwxk.text, 'lxml')
j_link = jwxk.noscript.meta.attrs['content'][6:]
c = requests.Session()
j_login = c.get(url=j_link,cookies = s.cookies.get_dict())
requests.utils.add_dict_to_cookiejar(c.cookies, {'sepuser': s.cookies.get_dict()['sepuser']}) # set jwxk cookies
# -------------------------------------------------------
cdata = { # Post Data
'subjectiveRadio': 103,
'subjectiveCheckbox': '110,',
'item_88': 5,
'item_89': 5,
'item_90': 5,
'item_92': 5,
'item_93': 5,
'item_94': 5,
'item_95': 5,
'item_96': 5,
'item_116': 5,
'item_117': 5,
'item_118': 5,
'item_119': 5,
'item_120': 5,
'item_122': 5,
'item_123': 5,
'item_124': 5,
'item_125': 5,
'item_126': 5,
'item_128': 5,
'item_129': 5,
'item_130': 5,
'item_131': 5,
'item_97': '课程与作业(包括作业、报告、测验测试、论文等)有助于我的能力的提高',
'item_98': '课程与作业(包括作业、报告、测验测试、论文等)有助于我的能力的提高',
'item_99': '课程与作业(包括作业、报告、测验测试、论文等)有助于我的能力的提高',
'item_100': '课程与作业(包括作业、报告、测验测试、论文等)有助于我的能力的提高',
'item_101': '课程与作业(包括作业、报告、测验测试、论文等)有助于我的能力的提高',
'radio_102': '103',
'item_108': '110,'
}
tdata = {
'subjectiveRadio': '',
'subjectiveCheckbox': '',
'item_133': 5,
'item_134': 5,
'item_136': 5,
'item_137': 5,
'item_139': 5,
'item_140': 5,
'item_141': 5,
'item_142': 5,
'item_143': 5,
'item_144': 5,
'item_148': 5,
'item_149': 5,
'item_150': 5,
'item_151': 5,
'item_152': 5,
'item_153': 5,
'item_155': 5,
'item_156': 5,
'item_157': 5,
'item_158': 5,
'item_159': 5,
'item_145': '治学严谨、备课充分、讲课认真、因材施教',
'item_146': '治学严谨、备课充分、讲课认真、因材施教'
}
# ---------------- Course Evaluation -------------------
print('Course Evaluation')
EvaPage = c.get("http://jwxk.ucas.ac.cn/evaluate/course/59586")
eva = BeautifulSoup(EvaPage.text, 'lxml')
hrefnum = re.compile(r"(\d+)")
for row in eva.find_all('tr'):
rowa = row.find_all('a')
if (len(rowa) < 4): continue
href = rowa[3].get('href')
rowstr = list(map(lambda x: x.string, rowa))
if (rowstr[3] == '评估'):
CourseNum = hrefnum.findall(href)[0]
res = c.post("https://jwxk.ucas.ac.cn/evaluate/saveCourseEval/" + CourseNum, data = cdata)
print(rowstr[0:4])
time.sleep(1)
print('Done')
# ---------------- Teacher Evaluation -------------------
print('Teacher Evaluation')
EvaPage = c.get("http://jwxk.ucas.ac.cn/evaluate/teacher/59586")
eva = BeautifulSoup(EvaPage.text, 'lxml')
hrefnum = re.compile(r"(\d+)")
for row in eva.find_all('tr'):
rowa = row.find_all('a')
if (len(rowa) < 4): continue
href = rowa[3].get('href')
rowstr = list(map(lambda x: x.string, rowa))
if (rowstr[3] == '评估'):
CourseNum = hrefnum.findall(href)[0]
TeacherNum = hrefnum.findall(href)[1]
res = c.post("https://jwxk.ucas.ac.cn/evaluate/saveTeacherEval/" + CourseNum + '/' + TeacherNum, data = tdata)
print(rowstr[0:4])
time.sleep(1)
print('Done')