-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
127 lines (110 loc) · 4.73 KB
/
run.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
from lxml import etree
import requests
import re
import hashlib
import base64
import execjs
import time
def MD5_HEX(str):
m = hashlib.md5()
b = str.encode(encoding='utf-8')
m.update(b)
str_md5 = m.hexdigest()
return str_md5
def get_js():
# f = open("D:/WorkSpace/MyWorkSpace/jsdemo/js/des_rsa.js",'r',encoding='UTF-8')
f = open("demo01.js", 'r', encoding='UTF-8')
line = f.readline()
htmlstr = ''
while line:
htmlstr = htmlstr + line
line = f.readline()
return htmlstr
class UESTC(object):
image_url = "http://xxxx.gxufe.edu.cn/cas/genValidateCode?dateTime=Sat"
url = "http://xxxx.gxufe.edu.cn/custom/js/SetKingoEncypt.jsp"
login_url = "http://xxxx.gxufe.edu.cn/cas/logon.action"
loginafter_url = "http://xxxx.gxufe.edu.cn/MainFrm.html"
def __init__(self, username, password):
self.__session = requests.session()
self.username = username
self.password = password
self.lists = []
self.time = int(time.time())
self.date = None
self.week = None
self.today = None
def login(self):
HEADERS = {
'Host': "xxxx.gxufe.edu.cn",
'User-Agent': "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER",
'Accept': "image/webp,image/*,*/*;q=0.8",
'Referer': "http://xxxx.gxufe.edu.cn/cas/login.action",
'Accept-Encoding': "gzip, deflate, sdch",
'Accept-Language': "zh-CN,zh;q=0.8"
}
HEADERS1 = {
'Host': "xxxx.gxufe.edu.cn",
'User-Agent': "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER",
'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"
}
Headers = {
'Accept': "text/plain, */*; q=0.01",
'Accept-Encoding': "gzip, deflate",
'Accept-Language': "zh-CN,zh;q=0.8",
'Connection': "keep-alive",
'Content-Length': "1124",
'Content-Type': "application/x-www-form-urlencoded",
'Host': "xxxx.gxufe.edu.cn",
'Origin': "http://xxxx.gxufe.edu.cn",
'Referer': "http://xxxx.gxufe.edu.cn/cas/login.action",
'User-Agent': "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER",
'X-Requested-With': "XMLHttpRequest"
}
username = self.username
password = self.password
txt_mm_expression = "12"
txt_mm_userzh = "0"
txt_mm_length = str(len(password))
image = self.__session.get(self.image_url, headers=HEADERS)
_sessionid = image.cookies.get("JSESSIONID")
with open('img2.png', 'wb') as f:
f.write(image.content)
# 识别验证码
import ddddocr
ocr = ddddocr.DdddOcr(beta=True)
with open("img2.png", 'rb') as f:
image = f.read()
res = ocr.classification(image)
print(res)
randnumber = res
# randnumber = input("请输入验证码:\n")
p_username = "_u" + randnumber
p_password = "_p" + randnumber
password1 = MD5_HEX(MD5_HEX(password) + MD5_HEX(randnumber))
username1 = username + ";;" + _sessionid
username1 = str(base64.b64encode(username1.encode("utf-8")), "utf-8")
rep = self.__session.get(self.url, headers=HEADERS)
text = rep.text
_deskey = re.search(r"var _deskey = '(.*?)';", text)
_nowtime = re.search(r"var _nowtime = '(.*?)';", text)
parms = p_username + "=" + username1 + "&" + p_password + "=" + password1 + "&randnumber=" + randnumber + "&isPasswordPolicy=1" + "&txt_mm_expression=" + txt_mm_expression + "&txt_mm_length=" + txt_mm_length + "&txt_mm_userzh=" + txt_mm_userzh
token = MD5_HEX(MD5_HEX(parms) + MD5_HEX(_nowtime.group(1)))
jsstr = get_js()
ctx = execjs.compile(jsstr)
_parms = str(base64.b64encode(ctx.call('strEnc', parms, _deskey.group(1)).encode("utf-8")), "utf-8")
data = 'params=' + _parms + '&token=' + token + "×tamp=" + _nowtime.group(1)
# data = 'params='+'&token='+"×tamp="+_nowtime.group(1)
res = self.__session.post(self.login_url, headers=Headers, data=data)
print(res.text)
def run(self):
self.login()
# self.evaluate()
if __name__ == '__main__':
# def run_():
username = input('请输入用户名:\n')
password = input('请输入密码:\n')
spider = UESTC(username, password)
spider.run()