-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxygz.py
23 lines (21 loc) · 848 Bytes
/
xygz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import urllib.request
import re
def getStuContent():
for i in range(1845, 5039, 2):
idNum = i
html = urllib.request.urlopen('http://www.xygz.com.cn/teacher/index.php?m=content&c=index&a=show&catid=210&id='
+ str(idNum)).read()
html = html.decode('gbk')
# print(html)
# 正则表达式 匹配数据 想要的数据加括号
# req = '<li><a href="(.*?)" title=".*?">(.*?)</a></li>'
name = '<h1>(.*?)</h1>'
school = 'button type="button" class="btn btn-danger btn-lg">(.*?)</button>'
names = re.findall(name, html)
schools = re.findall(school, html)
f = open('./test.txt', 'a')
f.write(str(names)+str(schools)+'\n')
# print(names, schools)
f.close()
if __name__ == '__main__':
getStuContent()