项目介绍

这是一个简单的小项目,可以用一句话来简单概括:

模拟登录数字杭电并爬取个人成绩

模拟登录

采用urllib包进行数据爬取,http.cookiejar进行cookie保存。

需要注意除了账号和加密后的密码,我们还需要传一个lt值。

1
2
3
4
5
6
7
def getLt():
getLtURL = 'http://cas.hdu.edu.cn/cas/login?service=http://i.hdu.edu.cn/dcp/index.jsp'
request = urllib.request.Request(getLtURL)
response = urllib.request.urlopen(request)
getLtContent = response.read().decode('utf-8')
getLt = re.search(r'value="(LT-.*?)"',getLtContent)
return getLt.group(1)

同时还有一个ST值在页面跳转的时候需要使用。

爬取个人成绩

只需要简单的正则匹配就可以了,这个就不多复述了。

最后放上我的代码:因为是随手之作,所以格式混乱,请领会精神

模拟登录数字杭电代码