曲师大抢课tool(python版)

相信大家已经被教务系统折腾的无可奈何..
于是他应(jian)运(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()
#教务系统的登陆
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("个人课表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)


#抢课系统
#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)
#查询个人课表
cxkb(a)
choseClass(510004,50,a)

实现了对教务系统的模拟登录,
使用过程:在选课期间获取课表后,查得课程号和课序号 然后 进行选课~代码抢课期间短短一小时写的 直接发上来了 …如若使用,可以自己再完善下。

你可能感兴趣的:(曲师大抢课tool(python版))