相信大家已經(jīng)被教務(wù)系統(tǒng)折騰的無(wú)可奈何..
于是他應(yīng)(jian)運(yùn)(qing)而(fu)出(dan)
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
headers = {
# 'Host': 'ids.qfnu.edu.cn',
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
# 'Referer': 'http://202.194.188.19/menu/top.jsp',
'Accept-Encoding': 'gzip, deflate, sdch',
'Accept-Language': 'zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4'
}
session = requests.session()
#教務(wù)系統(tǒng)的登陸
def login(username,password):
session = requests.session()
resp = session.get("http://ids.qfnu.edu.cn/authserver/login?service=http%3A%2F%2F202.194.188.19%2Fcaslogin.jsp", headers=headers)
print(resp.cookies)
bsObj = BeautifulSoup(resp.text, "html.parser")
lt = bsObj.find('input', {'name':'lt'})['value']
execution = bsObj.find('input', {'name':'execution'})['value']
print(lt)
print(execution)
params = {
'username': username,
'password': password,
'lt': lt,
'execution': 'e1s1',
'_eventId': 'submit',
'rmShown': '1'
}
resp = session.post("http://ids.qfnu.edu.cn/authserver/login?service=http%3A%2F%2F202.194.188.19%2Fcaslogin.jsp", data=params, headers=headers)
return session
#查詢自己的課表
def cxkb(session):
cxkb=session.get("http://202.194.188.19/xkAction.do?actionType=6")
with open("個(gè)人課表1.html", "w") as f:
f.write(cxkb.text)
#http://202.194.188.19/xkAction.do?actionType=2&pageNumber=19 get
def cxqk_kb(page,session):
for page in range(1,page+1):
r = session.get("http://202.194.188.19/xkAction.do?actionType=-1")
r = session.get("http://202.194.188.19/xkAction.do?actionType=2&pageNumber=-1&cx=ori")
#r = s.post("http://" + jwc_ip + "/xkAction.do", data = tparam, timeout = time_delay)
fy_url ='http://202.194.188.19/xkAction.do?actionType=2&pageNumber={page}'.format(page=page)
cxkb=session.get(fy_url)
print(cxkb.content)
with open("選課"+str(page)+".html", "w") as f:
f.write(cxkb.text)
#搶課系統(tǒng)
#http://202.194.188.19/xkAction.do kcId=520002_101&preActionType=2&actionType=9
def choseClass(kch,kxh,session):
kcId=str(kch)+'_'+str(kxh)
print(kcId)
params={
'kcId': kch+kxh,
'preActionType':'5',
'actionType':'9'
}
params1={
'kcId': kch+kxh,
'preActionType':'2',
'actionType':'9'
}
tparam = {
"kch": "510002",
"cxkxh": "29",
"kcm" : "",
"skjs": "",
"kkxsjc": "",
"skxq": "",
"skjc": "",
"pageNumber": "-2",
"preActionType": "2",
"actionType": "5"
}
r = session.get("http://202.194.188.19/xkAction.do?actionType=-1")
r = session.get("http://202.194.188.19/xkAction.do?actionType=2&pageNumber=-1&cx=ori")
r = session.post("http://202.194.188.19/xkAction.do", data = tparam)
resp = session.post("http://202.194.188.19/xkAction.do",data =params)
with open("test.html", "w") as f:
f.write(resp.text)
a=login('2016416xxx','xxx')
#choseClass('510004','50',a)
#查詢選課容量
#cxqk_kb(19,a)
#查詢個(gè)人課表
cxkb(a)
choseClass(510004,50,a)
實(shí)現(xiàn)了對(duì)教務(wù)系統(tǒng)的模擬登錄,
使用過(guò)程:在選課期間獲取課表后毡们,查得課程號(hào)和課序號(hào) 然后 進(jìn)行選課~代碼搶課期間短短一小時(shí)寫的 直接發(fā)上來(lái)了 ...如若使用,可以自己再完善下昧辽。