@hx
2018-04-26T00:42:38.000000Z
字数 1496
阅读 1662
Python
import requests
from bs4 import BeautifulSoup
if __name__ == "__main__":
def getData(myInfo):
# 首页
homeUrl = "http://uia.whxy.edu.cn/cas/login?service=http%3A%2F%2Fportal.whxy.edu.cn%2Fc%2Fportal%2Flogin"
# 登录
loginUrl = homeUrl + "%3Fredirect%3D%252Fweb%252Fguest%252Findex%26p_l_id%3D10213"
# 教务登录
jwLogin = "http://59.172.226.5/eams/sso/login.action"
# 教务主页
jwHome = "http://59.172.226.5/eams/home.action"
# 学籍信息
xj = "http://59.172.226.5/eams/stdDetail.action"
# 课表
kb = "http://59.172.226.5/eams/courseTableForStd.action"
kb2 = "http://59.172.226.5/eams/courseTableForStd!courseTable.action"
s = requests.Session()
r = s.get(homeUrl)
r.encoding = r.apparent_encoding
soup = BeautifulSoup(r.text, "html.parser")
lt = soup.find(attrs={"name": "lt"})["value"]
# 获取 lt
myInfo["lt"] = lt
myInfo["_eventId"] = "submit"
r = s.post(loginUrl, data=myInfo)
soup = BeautifulSoup(r.text, "html.parser")
# 一卡通余额
balance = soup.select_one("#balance").string
r = s.get(jwLogin)
r = s.get(jwHome)
r = s.get(xj)
soup = BeautifulSoup(r.text, "html.parser")
data_list = {"一卡通余额": balance}
for idx, tr in enumerate(soup.find_all('tr')):
for tdx, td in enumerate(tr.find_all("td")):
if len(td.contents) != 0:
if idx == 1 and tdx == 1:
data_list["学号"] = td.contents[0]
elif idx == 1 and tdx == 3:
data_list["姓名"] = td.contents[0]
elif idx == 2 and tdx == 3:
data_list["性别"] = td.contents[0]
elif idx == 5 and tdx == 3:
data_list["学院"] = td.contents[0]
elif idx == 6 and tdx == 1:
data_list["专业"] = td.contents[0]
elif idx == 11 and tdx == 3:
data_list["班级"] = td.contents[0]
print(data_list)
info = {"username": "2015****", "password": "Whxy27****"}
getData(info)