1 Star 0 Fork 0

asd/LoginJww

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Login_Jww.py 1.61 KB
一键复制 编辑 原始数据 按行查看 历史
FatTig3R 提交于 2018-03-26 20:58 . 完成对所以课程标题的抓取
import re
import requests
from bs4 import BeautifulSoup
txtUserID = int(input('Username:'))
txtPasswd = input('Password:')
login_URL = 'http://222.30.63.15/NKEMIS/SystemLogin.aspx'
headers = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.8",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"
}
# 获取CSRF验证
response = requests.get(login_URL, headers=headers)
bsObj = BeautifulSoup(response.text, 'lxml')
__VIEWSTATE = bsObj.find('input').attrs['value']
__EVENTVALIDATION = bsObj.find('input', id='__EVENTVALIDATION').attrs['value']
from_data = {
"__VIEWSTATE": __VIEWSTATE,
"__EVENTVALIDATION": __EVENTVALIDATION,
"txtUserID": txtUserID,
"txtPasswd": txtPasswd,
"ImageButton1.x": 1,
"ImageButton1.y": 1,
}
session = requests.session()
post = session.post(login_URL, data=from_data)
index_url = 'http://222.30.63.15/NKEMIS/Student/StudentDefault.aspx'
index_html = session.get(index_url) # 成功抓取
# print(index_html)
tbody_bsObj = BeautifulSoup(index_html.text, 'lxml')
# 课程相关标题
tr = tbody_bsObj.find('tr', {'class':'dgrdHeader'}).find_all('td')
for title, students_number, homework in zip(tr[0], tr[1], tr[-1]):
print(title + '\t\t', students_number + '\t\t', homework + '\t\t')
all_title = tbody_bsObj.find_all('a', style="color:red")
for title in all_title:
print(title.get_text().strip())
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/asdawdawdasd/LoginJww.git
git@gitee.com:asdawdawdasd/LoginJww.git
asdawdawdasd
LoginJww
LoginJww
master

搜索帮助