-
Notifications
You must be signed in to change notification settings - Fork 0
/
SongTian.py
188 lines (149 loc) · 5.33 KB
/
SongTian.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
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
import sys
import os
import re
import urllib.parse
import requests
from PIL import Image
from bs4 import BeautifulSoup
from lxml import etree
import ListUtil
import StrUtil
#from PyQt5.QtWidgets import QApplication, QWidget
from Course import Course
user = 0
url = "http://192.168.170.253/Default2.aspx"
#url = "http://jwxt.sontan.net"
S = requests.session()
header_code = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36",
"Referer": "http://192.168.170.253/",
#"Referer": "http://jwxt.sontan.net",
"Host": "192.168.170.253",
#"Host": "http://jwxt.sontan.net",
"Cache-Control": "max-age=0"
}
def addcour(res):
split_res = res.split('<br><br>')
for i in range(0,len(split_res)):
line = split_res[i]
if(str(line).startswith('<font')):
continue
else:
addc(line)
def addc(w):
w = w.split("<br>")
cname = w[0]
time = w[1]
tname = w[2]
pname = w[3]
print("2课名:" + cname)
print("2时间:" + time)
print("2老师:" + tname)
print("2地点:" + pname)
c = Course(cname, time, tname, pname)
StrUtil.loadBweek(c.getTime())
print(StrUtil.loadSweek(c.getTime()))
print(StrUtil.loadSection(c.getTime()))
ListUtil.addCourse(c)
def get_post_data(url):
re = S.get(url).text
soup = BeautifulSoup(re, 'lxml')
# user = input("学号: ")
# pwd = input("密码: ")
global user
user = 1908010101
pwd = "bali1626"
URL_CODE = "http://192.168.170.253/CheckCode.aspx" # 验证码地址
#URL_CODE = "http://jwxt.sontan.net/CheckCode.aspx" # 验证码地址
code = S.get(URL_CODE, headers=header_code)
with open("code.gif", "wb") as f:
f.write(code.content)
print("保存验证码到" + os.getcwd() + "/code.gif" + "\n")
image = Image.open('{}/code.gif'.format(os.getcwd()))
image.show()
checkCode = input("验证码: ")
viewState = soup.find('input', attrs={'name': '__VIEWSTATE'})['value']
# <form name="form1" method="post" action="Default2.aspx" id="form1">
# <input type="hidden" name="__VIEWSTATE" value="dDwyODE2NTM0OTg7Oz4=" />
login_info = {
# post data
"__VIEWSTATE": viewState,
# "__EVENTVALIDATION": '',
"txtUserName": user,
"TextBox2": pwd,
"txtSecretCode": checkCode,
"RadioButtonList1": "%D1%A7%C9%FA", # "学生".encode('gb2312','replace')
"Button1": "",
"lbLanauage": "",
"hidPdrs": "",
"hidsc": "",
}
return login_info
response = S.post(url, data=get_post_data(url), headers=header_code)
def getInfor(response, xpath):
content = response.content.decode('gb2312') # 网页源码是gb2312要先解码
selector = etree.HTML(content) # __Elements对象
infor = selector.xpath(xpath)[0] # xpath 寻找指定label
return infor # string
text = getInfor(response, '//*[@id="xhxm"]/text()')
text = text.replace(" ", "")
studentname = text.replace("同学", "")
print("姓名:" + studentname)
if studentname is None:
print("Login Failed")
else:
print("Login successfully")
urlStudentname = urllib.parse.quote_plus(str(studentname.encode('gb2312')))
class_header = {
#"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
#"Accept-Encoding": "gzip, deflate",
#"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7",
#"Host": "192.168.170.253",
"Referer": "http://192.168.170.253/xskbcx.aspx?xh="+str(user)+"&xm="+urlStudentname+"&gnmkdm=N121603",
#"Referer": "http://192.168.170.253/xskbcx.aspx?xh=1908010101&xm=%CB%D5%B3%AC%CF%CD&gnmkdm=N121603",
#"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36"
}
response = S.get("http://192.168.170.253/xskbcx.aspx?xh="+str(user)+"&xm="+urlStudentname+"&gnmkdm=N121603")
response = S.get("http://192.168.170.253/xskbcx.aspx?xh="+str(user)+"&xm="+urlStudentname+"&gnmkdm=N121603",headers=class_header)
html = response.content.decode("gb2312")
#print (html)
s = response.content.decode('gbk')
regex = '<td [\s\S]*?>([\s\S]*?)<\/td>'
pattern = re.compile(regex)
res= re.findall(pattern, s)
for i in range(0,18):
res.remove(res[0])
res = list(set(res))
res.remove(" ")
res.remove("晚上")
res.remove("下午")
for i in range(0,len(res)):
print("test2:" +(res[i]))
#w = str(res[i]).split("<br>")
addcour(res[i])
#ListUtil.printBweek2()
#ListUtil.printBweek3(Bweek)
#c.getIntTime(Sweek)
class Example(QWidget): #extend QWidget
def __init__(self): #父类构造器
super().__init__() #父级
self.initUI()
def initUI(self): #本类构造器
Bweek = input("请输入大周:")
Sweek = input("请输入小周:")
Section = input("请输入节数:")
c = ListUtil.getCourse(Bweek, Sweek, Section)
print(c.getCname())
print(c.getTname())
print(c.getPname())
print(c.getTime())
grid = ListUtil.initLabel(Bweek)
#grid = QGridLayout()
self.setLayout(grid)
self.move(300,150)
self.setWindowTitle("松田课表")
self.show()
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())