-
Notifications
You must be signed in to change notification settings - Fork 1
/
kp.py
131 lines (114 loc) · 4.27 KB
/
kp.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
# coding: utf-8
import requests
import re
import sys
import pytesseract
import os
from PIL import Image
print("欢迎使用沈阳工业大学自动教评系统。Github: github.com/647-coder/sut_kp。")
header = {"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Encoding":"gzip, deflate",
"Accept-Language":"zh-CN,zh;q=0.8",
"Cache-Control":"max-age=0",
"Connection":"keep-alive",
"Content-Type":"application/x-www-form-urlencoded",
"Upgrade-Insecure-Requests":"1",
"User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"}
username = None
passowrd = None
if len(sys.argv) >= 3:
username = sys.argv[1]
password = sys.argv[2]
else:
username = input('用户名 > ')
password = input('密码 > ')
print("正在登录...账号:{0} 密码:{1}".format(username, password))
session = requests.Session()
session.headers.update(header)
session.get("http://jwc.sut.edu.cn/")
tryflag = 1
while True:
res = session.get("http://jwc.sut.edu.cn/ACTIONVALIDATERANDOMPICTURE.APPPROCESS")
with open('vcode.jpg', 'wb') as f:
f.write(res.content)
im = Image.open('vcode.jpg')
try:
import pytesseract
vcode = pytesseract.image_to_string(im)
except ImportError:
im.show()
vcode = input('验证码 > ')
loginparams = {'WebUserNO': username,
'Password': password,
'Agnomen': vcode,
'submit.x': '30',
'submit.y': '20'}
login = session.post("http://jwc.sut.edu.cn/ACTIONLOGON.APPPROCESS",
data=loginparams)
loginpage = login.text
if u"个人信息" in loginpage:
print("登录成功!")
break
elif u"错误的" in loginpage:
print("用户名或密码错误。")
os._exit(1)
else:
print("自动识别验证码错误,正在重新尝试...")
if tryflag >= 3:
print("尝试次数,程序终止。")
os._exit(1)
tryflag += 1
session.get("http://jwc.sut.edu.cn/ACTIONJSATTENDAPPRAISE_001.APPPROCESS")
res = session.get("http://jwc.sut.edu.cn/ACTIONJSCHOSEAPPRAISESERIESID.APPPROCESS")
reg = "javascript:document.location='(.+)';"
com = re.compile(reg)
allurl = re.findall(com, res.text)
courses = []
for each in allurl:
tempurl = 'http://jwc.sut.edu.cn/' + each
res = session.get(tempurl)
page = res.text
courses += re.findall(com, page)
print("共发现 {0} 个需要课评的课程。".format(len(courses)))
i = 1
for each in courses:
tempurl = 'http://jwc.sut.edu.cn/' + each
res = session.get(tempurl)
page = res.text
reg1 = '<input type="hidden" name="SeriesID" value="([0-9]+)">'
reg2 = 'name="adjustCode" value="([0-9]+)"'
reg3 = '<input type="hidden" name="PaperID" value="([0-9]+)">'
reg4 = '<input type="hidden" name="TaskID" value="([0-9a-zA-Z]+)">'
reg5 = '<input type="hidden" name="TeacherNO" value="([0-9a-zA-Z&=]+)">'
reg6 = 'name="ResultID" value="(.+)" checked'
reg7 = 'type="radio" name="([0-9a-zA-Z_]+)" id='
com1 = re.compile(reg1)
com2 = re.compile(reg3)
com3 = re.compile(reg4)
com4 = re.compile(reg5)
com5 = re.compile(reg6)
com6 = re.compile(reg7)
com7 = re.compile(reg2)
params = {'ItemTypeScore1': "98",
'ItemTypeID': "1",
'SeriesID': str(re.findall(com1, page)[0]),
'PaperID': str(re.findall(com2, page)[0]),
'TaskID': str(re.findall(com3, page)[0]),
'TeacherNO': str(re.findall(com4, page)[0]),
'adjustCode': str(re.findall(com7, page)[0]),
'PaperScore': "98",
'ResultMemo': "",
'Score1_1': '100',
'Score1_2': '100',
'Score1_3': '100',
'Score1_4': '100',
'Score1_5': '100',
'Score1_6': '80',
'Score1_7': '100',
'ResultID': ['1_1', '1_2', '1_3', '1_4', '1_5', '1_6', '1_7']}
print("课评进度({0}/{1})...".format(i, len(courses)))
i += 1
session.post("http://jwc.sut.edu.cn/ACTIONJSUPDATECONTENTRESULT.APPPROCESS",
data=params)
print("已全部完成!")
os._exit(0)