使用python的上海大学抢课方案
此为自己写的抢课脚本,适用于课程限制人数后有人退课的情况。且可以在选课成功后给qq邮箱发送邮件(但需要qq等可以配置smtp的邮箱!)
####使用教程####
1.下载安装pycharm
2.下载chromedriver 并放在同一目录下
3.根据自己需要更改学号,课号等
4.芜湖,起飞!把电脑开着、链接校园网后挂着脚本就行
如有bug请告知我,谢谢!(概率更新)
from selenium import webdriverimport time
import smtplib
from email.mime.text import MIMEText
from email.header import Headername=#填入学号
passnum=#填入密码
emailname=#填入qq邮箱
emailpw=#输入邮箱密码(需要申请smtp,具体是什么自己网上查):选课成功了可以发邮件给邮箱cid=['08305144','08305144']#课程号
tid=['1001','1005']#教师号path=r'C:.\chromedriver.exe'#同文件夹下放一个chromedriveroption = webdriver.ChromeOptions()
#option.add_argument('headless')
option.add_experimental_option("excludeSwitches", ['enable-automation','enable-logging'])
driver = webdriver.Chrome(executable_path= path, chrome_options=option)#登录
def login1():driver.get('https://oauth.shu.edu.cn/login/eyJ0aW1lc3RhbXAiOjE2MTA1MjQ5ODA1MTgwNDM2MDgsInJlc3BvbnNlVHlwZSI6ImNvZGUiLCJjbGllbnRJZCI6InlSUUxKZlVzeDMyNmZTZUtOVUN0b29LdyIsInNjb3BlIjoiIiwicmVkaXJlY3RVcmkiOiJodHRwOi8veGsuYXV0b2lzcC5zaHUuZWR1LmNuL3Bhc3Nwb3J0L3JldHVybiIsInN0YXRlIjoiIn0=')driver.find_element_by_name("username").click()driver.find_element_by_name("username").send_keys(name)driver.find_element_by_xpath("//*[@id=\"password\"]").click()driver.find_element_by_xpath("//*[@id=\"password\"]").send_keys(passnum)driver.find_element_by_xpath("//*[@id=\"submit-button\"]").click()driver.get('http://xk.autoisp.shu.edu.cn/Home/TermIndex')driver.find_element_by_xpath("/html/body/form/div/table/tbody").click()driver.find_element_by_xpath("/html/body/form/div/button").click()#查询所有课程 若有空余的课 则输出i
def query1():while (1):for i in range(len(cid)):time.sleep(1)# 登录网页 输入课程号和教师号driver.get('http://xk.autoisp.shu.edu.cn/StudentQuery/QueryCourse')#退出登录就重新登录while (driver.current_url != 'http://xk.autoisp.shu.edu.cn/StudentQuery/QueryCourse'):login1()driver.get('http://xk.autoisp.shu.edu.cn/StudentQuery/QueryCourse')driver.find_element_by_name("CID").click()driver.find_element_by_name("CID").send_keys(cid[i])driver.find_element_by_name("TeachNo").click()driver.find_element_by_name("TeachNo").send_keys(tid[i])# 查询driver.find_element_by_xpath("//*[@id=\"QueryAction\"]").click()# a是容量 b是现在人数a = int(driver.find_element_by_xpath("//*[@id=\"divMainContent\"]/table/tbody/tr[2]/td[9]").text)b = int(driver.find_element_by_xpath("//*[@id=\"divMainContent\"]/table/tbody/tr[2]/td[10]").text)if(a>b):return icla=[]
#先登录
login1()
while(1):i=query1()#cla变成有空余的课程名cla=[driver.find_element_by_xpath("//*[@id=\"divMainContent\"]/table/tbody/tr[2]/td[2]").text]#去快速选课页面 输入课程号driver.get('http://xk.autoisp.shu.edu.cn/CourseSelectionStudent/FastInput')while (driver.current_url != 'http://xk.autoisp.shu.edu.cn/CourseSelectionStudent/FastInput'):login1()driver.get('http://xk.autoisp.shu.edu.cn/CourseSelectionStudent/FastInput')while(1):try:time.sleep(1)driver.find_element_by_name('cids[0]').click()driver.find_element_by_name('cids[0]').send_keys(cid[i])driver.find_element_by_name('tnos[0]').click()driver.find_element_by_name('tnos[0]').send_keys(tid[i])driver.find_element_by_xpath('//*[@id="FastInputAction"]').click()except Exception:print("error.2")else:break#获取提示信息ans=''while(1):try:ans=driver.find_element_by_xpath('//*[@id="divOperationResult"]/table/tbody/tr[2]/td[6]').textprint(ans);except Exception:print("error.Last")else:breakif '选课失败!已选' in ans :driver.get('http://xk.autoisp.shu.edu.cn/CourseReturnStudent/CourseReturn')while(driver.current_url != 'http://xk.autoisp.shu.edu.cn/CourseReturnStudent/CourseReturn'):login1()driver.get('http://xk.autoisp.shu.edu.cn/CourseReturnStudent/CourseReturn')nm='input[cid="'+cid[i]+'"][tno]'driver.find_element_by_css_selector(nm).click()driver.find_element_by_id("btnReturnClass").click()alert = driver.switch_to_alert()alert.accept()#选课成功 发邮件if '选课成功'in ans :print('选课成功',cla)message = MIMEText('Lesson Chosen Successfully', 'plain', 'utf-8')message['From'] = Header('Democracy<'+emailname+'>', 'utf-8')message['To'] = Header('Democracy<'+emailname+'>', 'utf-8')message['Subject']=Header(cla[0],'utf-8')smtp = smtplib.SMTP_SSL('smtp.qq.com')# smtp.connect('smtp.qq.com',465)smtp.login(emailname, emailpw)smtp.sendmail(emailname, emailname, message.as_string())smtp.quit()tmp=cid[i]del cid[i]del tid[i]for j in range(len(cid)):if cid[j]==tmp:del cid[j]del tid[j]time.sleep(3)
driver.quit()
使用python的上海大学抢课方案相关推荐
- FreeCAD C/C++/Python混合开发/调试方案
FreeCAD C/C++/Python混合开发/调试方案 济南友泉软件有限公司 本文主要讲述在Visaul Studio 2019中混合调试FreeCAD C/C++/Python代码的环境配置方法 ...
- 【Python】可视化配色方案自由啦 (Python版)
本文分享一个Python快速提取任何图片配色方案的工具:Haishoku: Haishoku 是一个用来获取图片主色调和主要配色方案的python库,依赖于python3和pillow. Haisho ...
- 使用python实现智能浇筑方案
具体方案如下所示: 根据这个地图,我们构建1010矩阵,大概草图如下所示: 然后,根据之前的设计要求,我们假设浇筑满的时间为t1~tN. 然后浇筑的速度随着时间的变换而逐渐变小,假设其流速的函数为 然 ...
- 亲测可用,利用Python实现自动抢课脚本
借助pyautogui库,我们可以轻松地控制鼠标.键盘以及进行图像识别,实现自动抢课的功能 1.准备工作 我们在仓库里提供了2个必须的文件,包括: auto_get_lesson_pic_recogn ...
- python 运行日志logging代替方案
以下是自己写的 记录日志的代码.(和logging不搭嘎,如果如要学loggging模块,本文末尾有他人的链接.) # prtlog.py ############################## ...
- 超硬核Python避坑学习方案奉上!入门到就业一篇就搞定!
本文收录了python从基础入门到高级进阶,再到之后发展方向的详细介绍,欢迎小伙伴们关注阅读!相信对你的python学习之路定能助一臂之力!评论提出你的见解!大家一起为你解答! 目录 一.迈出开发的第 ...
- 8种用Python实现定时执行任务的方案,一定有你用得到的
我们在日常工作中,常常会用到需要周期性执行的任务. 一种方式是采用 Linux 系统自带的 crond 结合命令行实现: 一种方式是直接使用Python: 于是我把常见的Python定时任务实现方法整 ...
- 【华为OD机试真题 java、python】硬件产品销售方案(100%通过+复盘思路)
代码请进行一定修改后使用,本代码保证100%通过率,本题提供java.python两种代码.复盘思路在文章的最后 题目描述 某公司目前推出了AI开发者套件,AI加速卡,AI加速模块,Ai服务器,智能边 ...
- 【华为OD机试真题 python】硬件产品销售方案【2023 Q1 | 200分】
■ 题目描述 [硬件产品销售方案] 某公司目前推出了AI开发者套件,AI加速卡,AI加速模块,AI服务器,智能边缘多种硬件产品,每种产品包含若干个型号. 现某合作厂商要采购金额为amount元的硬件产 ...
最新文章
- mysql-理想的索引
- 《Hack与HHVM权威指南》——1.5.2 覆盖方法的类型
- Css相对定位和绝对定位实现CSDN标题栏
- 广州站 | 云原生 Serverless 技术实践营精彩回顾
- error2---BeginPath和EndPath之间的TextOut无法显示
- Codeforces 918D/917B - MADMAX
- wxpython使用方法_python图形界面开发之wxPython树控件使用方法详解
- Python urllib2和urllib的使用
- 查看主机DNSserver
- python的raw_对于Python中RawString的理解(引用)
- php 伪静态 获取当前页面路径_php url伪静态过程详解
- 烘培赛道的2021:资本重押下,老字号向左,新秀向右?
- python从0到1_从0到1的Python学习经验
- 青少年qsnctf [登录试试] 攻略
- 云服务器(CentOS 7)上面部署Node.js环境
- UART串口通信常用协议对比——rs232、485的区别
- 智能网联汽车信息安全实训平台-IVI(或T-BOX)的WiFi攻击实验
- TensorFlow发布Eager,便于Debug!
- Python打包exe程序(pyinstaller)以及打包文件太大的解决方法
- qDebug()的使用方法
热门文章
- iif函数 vfp_VFP常用函数大全
- [最完整的前端学习手册]——ES6语法
- 学用ORACLE AWR和ASH特性(4)-生成指定SQL的统计报表
- 关于视频播放的一些总结
- “信息科技“ 纳入义务教育,少儿编程程首选项
- PC1 ping PC2 步骤
- Ucinet 分析结果数据不对齐怎么办?
- 窗口DEA及matlab应用,文后有网盘链接
- 2022考研王道计算机408pdf(王道计算机组成原理+王道操作系统+王道计算机网络+王道数据结构)
- 实战|应急响应之某公司的粗心导致网站被恶意篡改