Record study record life
爬虫实现集美大学(JMU)抢课
爬虫实现集美大学(JMU)抢课

爬虫实现集美大学(JMU)抢课

2022/8/29将程序打包为exe文件,不依赖python环境

exe文件下载请qq或vx联系本人->联系方式在博客主页关于页面

抢课中与抢课成功示例

使用教程

进入这些页面按F12点击网络,然后刷新页面就会出现这些东西

cookie(下图圈起来的地方)

没有就刷新哦

课程号(左边的课程和右边(std-count一一对应))

id1(下图链接圈起来部分,每个人都不同)

id2(下图链接圈起来部分,每个人都不同)

运行后不必关闭,时间到的一瞬间一般就自动抢上了

(本人自己以及帮他人抢了10余门网课,亲测有效)

若课程已满也可以让该程序运行,一旦有人退课就会自动抢上;一般也能捡漏到。


强调

使用super_qiangke.py需要自己配置Selenium,而lpython版本可以直接挂载在服务器上或者在自己电脑上直接运行,也可以设置定时任务,到点自动抢课 直接post数据包到学校服务器进行抢课,可以防止选课时人多网站很卡

使用说明

  • 学生信息需要更改即需要改   id1 id2  ,这两个id分别就是选课界面的链接里面会有的两个数字如“#http://jwxt.jmu.edu.cn/student/for-std/course-select/4759/turn/1621/select”此处id1=4759,id2=1621;不同开放的选课界面的id都会不同
  • lessonAssoc课程号非页面的课程代码,需按F12
  • 然后点击网络,刷新页面,点击名称中一个叫std-cout的选项,其中的预览就是整个页面的对应的课程号
  • 最后需要更改cookie如前面的图片一样获取

以上数据都可以从前面的图片一样的操作

Python抢课代码(直接python运行就行)(推荐)

import json
import re
import requests
import time
import datetime
#--------------------------------------------------------
#只有这部分的信息可能需要修改 cookie = "SESSION=9c637549-f300-4406-a7c5-8fca66636a19; __pstsid__=cb1cb095326152424226338f0d7b2404; _sp_id.acfd=816ef727-feba-45dc-9088-1cf6bee65d7a.1668868858.1.1668868858.1668868858.1e1e3108-ce79-4096-9f6b-bc35e5446a5c"# 账号信息 turn = ""#可不填 requestId = ""#可不填 response = ""#可不填 lessonAssoc = 228301 # 课程信息,课程号 #http://jwxt.jmu.edu.cn/student/for-std/course-select/4759/turn/1621/select id1=4759#链接上的y第一串数值 id2=2441#链接上的第二串数值 virtualCoist=0#意愿值设置,若不为第一轮抢课,则无需意愿值可设为0
#---------------------------------------------------------
# add-predicate(包含课程信息) def add_predicate(requestId): print("正在add-predicate...(其中包含课程信息)") url = " http://jwxt.jmu.edu.cn/student/ws/for-std/course-select/add-predicate" headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.39", "Cookie": cookie, "Host": "jwxt.jmu.edu.cn", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9", "Connection": "keep-alive", "Content-Length": "159", "Content-Type": "application/json", "Origin": "http://jwxt.jmu.edu.cn" # "Referer":f"http://jwxt.jmu.edu.cn/student/for-std/course-select/4759/turn/{turn}/select" } date = {"studentAssoc": id1, "courseSelectTurnAssoc": id2, "requestMiddleDtos": [ { "lessonAssoc": lessonAssoc, "virtualCost": 0, "scheduleGroupAssoc": None} ], "coursePackAssoc": None } date = json.dumps(date) # print(type(date)) response = requests.post(url=url, headers=headers, data=date, verify=False) # print(type(response)) print(response.content) # print(type(response.content)) # print(response.status_code) requestId = (response.content) return requestId # predicate-response def predicate_response(response): print("正在predicate-response...") url = "http://jwxt.jmu.edu.cn/student/ws/for-std/course-select/predicate-response" headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.30", "Cookie": cookie, "Host": "jwxt.jmu.edu.cn", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9", "Connection": "keep-alive", "Content-Length": "61", "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "Origin": "http://jwxt.jmu.edu.cn", "Referer": f"http://jwxt.jmu.edu.cn/student/for-std/course-select/4759/turn/{turn}/select" } date = { "studentId": id1, "requestId": requestId } response = requests.post(url=url, headers=headers, data=date, verify=False) print(response.text) return response # add-request def add_request(requestId): print("正在add-request...(包含课程信息)") url = "http://jwxt.jmu.edu.cn/student/ws/for-std/course-select/add-request" headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.30", "Cookie": cookie, "Host": "jwxt.jmu.edu.cn", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9", "Connection": "keep-alive", "Content-Length": "136", "Content-Type": "application/json", "Origin": "http://jwxt.jmu.edu.cn", "Referer": f"http://jwxt.jmu.edu.cn/student/for-std/course-select/4759/turn/{turn}/select" } date = {"studentAssoc": id1, "courseSelectTurnAssoc": id2, "requestMiddleDtos": [{"lessonAssoc": lessonAssoc, "virtualCost": virtualCoist, "scheduleGroupAssoc": None}]} date = json.dumps(date) response = requests.post(url=url, headers=headers, data=date, verify=False) print(response.content) requestId = response.content return requestId # add-drop-response def add_drop_response(): print("正在add-drop-response...") url = "http://jwxt.jmu.edu.cn/student/ws/for-std/course-select/add-drop-response" headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.30", "Cookie": cookie, "Host": "jwxt.jmu.edu.cn", "Accept-Encoding": "gzip, deflate", "Accept-Language": "zh-CN,zh;q=0.9", "Connection": "keep-alive", "Content-Length": "136", "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "Origin": "http://jwxt.jmu.edu.cn", "Referer": f"http://jwxt.jmu.edu.cn/student/for-std/course-select/4759/turn/{turn}/select" } date = { "studentId": id1, "requestId": requestId } response = requests.post(url=url, headers=headers, data=date, verify=False) print(response.text) result = response.text issuccess="false" try: tishi = re.compile(r'.*?,"text":"(?P.*?)"}', re.S) tishi = re.search(tishi, result).group("tishi") print("选课结果提示:" + tishi) except Exception as cuowu: print("无提示!", cuowu) try: jieguo = re.compile(r'.*?,"success":(?P.*?),"', re.S) issuccess = re.search(jieguo, result).group("issuccess") print("选课结果:" + issuccess) except Exception as cuowu: print("无结果!", cuowu) return issuccess if __name__ == '__main__': ## scheduled_time_hour = 9 # 将时间定为30s ## scheduled_time_minute = 12 # 将时间定为30s ## scheduled_time_second = 20 # 将时间定为30s ## while True: ## now = datetime.datetime.now().replace(microsecond=0) ## if now.hour == scheduled_time_hour and now.minute == scheduled_time_minute and now.second == scheduled_time_second: ## print(now) ## break; # 获取turnId issuccess = "false" while (issuccess == "false"): try: # add-predicate(包含课程信息) requestId = add_predicate(requestId) # predicate-response response = predicate_response(response) # add-request requestId = add_request(requestId) # add-drop-response issuccess=add_drop_response() except Exception: print("发生异常...")

Selenium抢课代码(需要安装selenium)

import datetime
import json
import re
import time
import urllib
from selenium import webdriver
import requests
cookie=""#账号信息
turn=""
requestId=""
response=""
username=input("请输入你的学号:")
password=input("请输入你的密码:")
# lessonAssoc=int(input("请输入你要学的课程号:"))#课程信息,课程号
lessonAssoc=198864
studentId=4759
courseSelectTurnAssoc=1781
#获取cookie
def get_cookie():
    EDGE = {
        "browserName": "MicrosoftEdge",
        "version": "99.0.1150.39",
        "platform": "WINDOWS",
        "ms:edgeOptions": {
            'extensions': [],
            'args': [
                '--headless',
                '--disable-gpu'
            ]}
    }  #设置为无头模式
    driver = webdriver.Edge(executable_path="C:\Program Files (x86)\Microsoft\Edge\Application\msedgedriver.exe", capabilities=EDGE)  # Edge浏览器"C:\Program Files (x86)\Microsoft\Edge\Application\msedgedriver.exe"
    driver.get('https://cas.paas.jmu.edu.cn/cas/login?service=http%3A%2F%2Fjwxt.jmu.edu.cn%2Fstudent%2Fsso%2Flogin')
    print(driver.title)
    # username=driver.find_element_by_xpath('//*[@id="username"]')
    # username.click()#点击事件
    # 找到用户名然后输入账号
    driver.find_element_by_xpath('//*[@id="username"]').send_keys(username)
    # 找到密码框然后输入密码
    driver.find_element_by_xpath('//*[@id="password"]').send_keys(password)
    # 找到登陆按钮并点击登陆
    driver.find_element_by_xpath('//*[@id="fm1"]/div[4]/div/input[7]').click()
    time.sleep(3)
    print(driver.title)
    # 找到选课按钮并单机,进入选课系统页面
    driver.find_element_by_xpath('//*[@id="app"]/div/div[1]/div/div/div[4]/div/div[2]/div[2]/div/div[1]/div/div[3]/div[2]/div[1]/div/div[1]').click()
    # 关闭子窗口
    driver.close()
    # 切换窗口,选择-1及最后一个窗口
    handles = driver.window_handles  # 再次获取窗口句柄handles
    # print('新窗口句柄为:{0}'.format(handles))
    # 新老句柄列表可以看出,新出现的句柄在列表里面排在后面
    driver.switch_to.window(handles[-1])  # 执行切换窗口操作
    print(driver.title)

    SESSION = driver.get_cookie("SESSION")
    # print(SESSION['value'])
    SESSION = SESSION['value']
    __pstsid__ = driver.get_cookie("__pstsid__")
    # print(__pstsid__['value'])
    __pstsid__ = __pstsid__['value']
    cookie = f'SESSION={SESSION}; __pstsid__={__pstsid__}'
    print(cookie)
    return cookie








#获取turnId
def getturn(turn):
    url=" http://jwxt.jmu.edu.cn/student/ws/for-std/course-select/open-turns"
    headers={
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.39",
        "Cookie": cookie,
        "Host": "jwxt.jmu.edu.cn",
        "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
        "Connection":"keep-alive",
        "Content-Length": "42",
        "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
        "Origin":"http://jwxt.jmu.edu.cn",
        "Referer":"http://jwxt.jmu.edu.cn/student/for-std/course-select/single-student/turns"
    }
    date={
    "bizTypeId": 2,
    "studentId": studentId,
    "departmentId": 17
          }
    response=requests.post(url=url, headers=headers, data=date,verify=False)
    all_course=response.json()
    print("可选择的板块----从0开始按顺序排序如下")
    number=0;
    for i in all_course:
        print(number,i)
        number+=1

    youchoice=int(input("请输入你选择的板块(从0开始)"))
    turn=all_course[youchoice]['id']
    print(turn)
    return turn



#add-predicate(包含课程信息)
def add_predicate(requestId):
    print("正在add-predicate...(其中包含课程信息)")
    url=" http://jwxt.jmu.edu.cn/student/ws/for-std/course-select/add-predicate"

    headers={
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.39",
        "Cookie": cookie,
        "Host": "jwxt.jmu.edu.cn",
        "Accept-Encoding": "gzip, deflate",
        "Accept-Language": "zh-CN,zh;q=0.9",
        "Connection":"keep-alive",
        "Content-Length": "159",
        "Content-Type":"application/json",
        "Origin":"http://jwxt.jmu.edu.cn"
        #"Referer":f"http://jwxt.jmu.edu.cn/student/for-std/course-select/4759/turn/{turn}/select"
    }
    date={"studentAssoc":studentId,
          "courseSelectTurnAssoc":courseSelectTurnAssoc,
          "requestMiddleDtos":[
              {
                  "lessonAssoc":lessonAssoc,
                  "virtualCost":0,
                  "scheduleGroupAssoc":None}
          ],
          "coursePackAssoc":None
          }
    date= json.dumps(date)
    print(type(date))
    response=requests.post(url=url, headers=headers, data=date,verify=False)
    #print(type(response))
    print(response.content)
    #print(type(response.content))
    #print(response.status_code)
    requestId=(response.content)
    return requestId


#predicate-response
def predicate_response(response):
    print("正在predicate-response...")
    url="http://jwxt.jmu.edu.cn/student/ws/for-std/course-select/predicate-response"

    headers={
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.30",
        "Cookie":cookie,
        "Host": "jwxt.jmu.edu.cn",
        "Accept-Encoding": "gzip, deflate",
        "Accept-Language": "zh-CN,zh;q=0.9",
        "Connection":"keep-alive",
        "Content-Length": "61",
        "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
        "Origin":"http://jwxt.jmu.edu.cn",
        "Referer":f"http://jwxt.jmu.edu.cn/student/for-std/course-select/4759/turn/{turn}/select"
    }
    date={
        "studentId": studentId,
        "requestId": requestId
    }

    response=requests.post(url=url, headers=headers, data=date,verify=False)
    print(response.text)
    return response



#add-request
def add_request(requestId):
    print("正在add-request...(包含课程信息)")
    url="http://jwxt.jmu.edu.cn/student/ws/for-std/course-select/add-request"

    headers={
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.30",
        "Cookie":cookie,
        "Host": "jwxt.jmu.edu.cn",
        "Accept-Encoding": "gzip, deflate",
        "Accept-Language": "zh-CN,zh;q=0.9",
        "Connection":"keep-alive",
        "Content-Length": "136",
        "Content-Type":"application/json",
        "Origin":"http://jwxt.jmu.edu.cn",
        "Referer":f"http://jwxt.jmu.edu.cn/student/for-std/course-select/4759/turn/{turn}/select"
    }
    date={"studentAssoc":studentId,"courseSelectTurnAssoc":courseSelectTurnAssoc,"requestMiddleDtos":[{"lessonAssoc":lessonAssoc,"virtualCost":0,"scheduleGroupAssoc":None}]}
    date= json.dumps(date)
    response=requests.post(url=url, headers=headers, data=date,verify=False)
    print(response.content)
    requestId=response.content
    return requestId


#add-drop-response
def add_drop_response():
    print("正在add-drop-response...")
    url="http://jwxt.jmu.edu.cn/student/ws/for-std/course-select/add-drop-response"

    headers={
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.30",
        "Cookie":cookie,
        "Host": "jwxt.jmu.edu.cn",
        "Accept-Encoding": "gzip, deflate",
        "Accept-Language": "zh-CN,zh;q=0.9",
        "Connection":"keep-alive",
        "Content-Length": "136",
        "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
        "Origin":"http://jwxt.jmu.edu.cn",
    }
    date={
    "studentId": studentId,
    "requestId": requestId
    }

    response = requests.post(url=url, headers=headers, data=date, verify=False)
    print(response.text)
    result = response.text
    issuccess = "false"
    try:
        tishi = re.compile(r'.*?,"text":"(?P.*?)"}', re.S)
        tishi = re.search(tishi, result).group("tishi")
        print("选课结果提示:" + tishi)
    except Exception as cuowu:
        print("无提示!", cuowu)
    try:
        jieguo = re.compile(r'.*?,"success":(?P.*?),"', re.S)
        issuccess = re.search(jieguo, result).group("issuccess")
        print("选课结果:" + issuccess)
    except Exception as cuowu:
        print("无结果!", cuowu)
    return issuccess

if __name__ == '__main__':
    # scheduled_time_hour = 8  # 将时间定为8h
    # scheduled_time_minute = 59  # 将时间定为59min
    # scheduled_time_second = 58  # 将时间定为58s
    # while True:
    #     now = datetime.datetime.now().replace(microsecond=0)
    #     if now.hour == scheduled_time_hour and now.minute == scheduled_time_minute and now.second == scheduled_time_second:
    #         print(now)
    #         break;

    # 获取turnId
    result="false"
    cookie=get_cookie()
    # turn=getturn(turn)
    issuccess = "false"
    while (issuccess == "false"):

        # add-predicate(包含课程信息)
        requestId=add_predicate(requestId)
        # predicate-response
        response=predicate_response(response)
        # add-request
        requestId=add_request(requestId)
        # add-drop-response
        issuccess=add_drop_response()

    # # 获取turnId
    # issuccess = "false"
    # while (issuccess == "false"):
    #     try:
    #         # add-predicate(包含课程信息)
    #         requestId = add_predicate(requestId)
    #         # predicate-response
    #         response = predicate_response(response)
    #         # add-request
    #         requestId = add_request(requestId)
    #         # add-drop-response
    #         issuccess = add_drop_response()
    #     except Exception:
    #         print("发生异常...")

赞赏

微信赞赏 支付宝赞赏

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

2条评论