中科大EPC抢预约考试脚本简单版
生活随笔
收集整理的這篇文章主要介紹了
中科大EPC抢预约考试脚本简单版
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
中科大EPC搶課和預約考試腳本簡單版
- 一、前言
- 二、代碼
- 三、效果與總結
一、前言
源于EPC約考,每次開放名額很少,用腳本比在網頁快的多。使用Python3,涉及requests和re模塊。
second_id 的獲取:
cookies 的獲取:
二、代碼
使用的是Jupyter
import requests import time import re #############全局變量管理################## second_id="xxxx"#個人id baseURL="https://epc.ustc.edu.cn/" # 偽造請求頭 req_header = {'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36','Content-Type': 'application/x-www-form-urlencoded' } #cookie 信息 從瀏覽器獲得 該方法避免了 繁瑣的 登錄驗證碼識別 cookies_str="_ga=GA1.3.1307624726.1604932641; sduuid=4d3318d9dxxxx" # 解析cookie def SetCookies(cookies_str):cookies={}kv_list=cookies_str.split(';')for kv in kv_list:l=kv.split("=")cookies[l[0]]=l[1]+";Path=/; Domain=.jw.ustc.edu.cn; "return cookies #獲取 提交 鏈接 def getPostURL(weeks,days,second_id):try:chaxun_url="https://epc.ustc.edu.cn/m_service.asp?second_id="+second_id+"&week_day="+str(days)+"&week="+str(weeks)response = requests.get(chaxun_url, headers=req_header,cookies=SetCookies(cookies_str))if response.status_code==200:patten='exam</td>\r\n\t\t\t\t\t\t\t\t\t<td align="center">(.*?)'#第幾周patten+='</td>\r\n\t\t\t\t\t\t\t\t\t<td align="center">(.*?)'#周幾patten+='</td>\r\n\t\t\t\t\t\t\t\t\t<td align="center">(.*?)'#考試時間patten+='</td>\r\n\t\t\t\t\t\t\t\t\t<td align="center">(.*?)'#教室patten+='</td>\r\n\t\t\t\t\t\t\t\t\t<td align="center">(.*?)'#預約開始時間patten+='</td>\r\n\t\t\t\t\t\t\t\t\t<td align="center">(.*?)'#預約截至時間patten+='</td>\r\n\t\t\t\t\t\t\t\t\t<td align="center">(.*?)'#可預約patten+='</td>\r\n\t\t\t\t\t\t\t\t\t<td align="center">(.*?)'#已預約patten+='</td>\r\n\t\t\t\t\t\t\t\t\t<td align="center">(.*?)'#學時m1=re.findall(patten, response.text)m2=re.findall('<form action="(.*?)" method="post"', response.text)return True,m1,m2else:print("請求失敗")return False,[],[]except Exception as e:print(e)return False,[],[] # 選課提交 def XuanKe(url):try:URL=baseURL+urlparams={"submit_type":"book_submit",}# book_cancelresponse = requests.post(URL, data=params, headers=req_header,cookies=SetCookies(cookies_str))if response.status_code==200:return Trueexcept Exception as e:print(e)return False # 任務包裝 def run():flag,m1,m2=getPostURL(17,2,second_id)#搶第17周,周二的課if flag:for i in m1:print(i)passfor i in m2:flag=XuanKe(i)if flag:#print(text)passelse:print("腳本有誤!") # 主函數 def main():for i in range(100000):start=time.time()run()print("第"+str(i+1)+"次請求,請求時間:"+str(round(time.time()-start,2))+"秒")#time.sleep(3)#延時0.5s三、效果與總結
我準備搶的是,17周,周二的考試,13:30開搶,我提前1分鐘在跑腳本,結果第一個搶到
總結
以上是生活随笔為你收集整理的中科大EPC抢预约考试脚本简单版的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java:从99瓶子数到0,一个int、
- 下一篇: English trip -- VC(情