├── README.md └── qiangzhi_select_courses.py /README.md: -------------------------------------------------------------------------------- 1 | # 强智教务系统自动抢课 2 | 帮助广大学生解决抢不到好课的问题!自动抢课!! 3 | 100行代码帮你实现抢课! 4 | 使用了python中splinter的API接口用来操作页面交互,用了twilio用来给手机发送短信通知抢课成功!细节讲解在py代码中。 5 | 6 | 欢迎大家fork来继续增加更多功能,我也会不定期更新功能! 7 | splinter API文档链接:https://splinter.readthedocs.io/en/latest/mouse-interaction.html 8 | 我的博客链接:https://home.cnblogs.com/u/xubin97/ 更多这方面文章! 9 | -------------------------------------------------------------------------------- /qiangzhi_select_courses.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Fri Jan 18 17:26:38 2019 4 | 5 | @author: lenovo 6 | """ 7 | from selenium.webdriver.chrome.options import Options 8 | from splinter.browser import Browser 9 | from browsermobproxy import Server 10 | from time import sleep 11 | from twilio.rest import Client 12 | 13 | #获取所有网络请求 14 | server=Server("D:/splinter/browsermob-proxy-2/browsermob-proxy-2.1.4/bin/browsermob-proxy") 15 | server.start() 16 | proxy=server.create_proxy() 17 | 18 | chrome_options=Options() 19 | chrome_options.add_argument('--proxy-server={host}:{port}'.format(host='localhost',port=proxy.port)) 20 | #disable-infobars 21 | class HuoChe(object): 22 | 23 | """docstring for Train""" 24 | driver_name='Chrome' 25 | executable_path='D:\爬虫实战\12306\chromedriver_win32' 26 | #用户名 密码 27 | username = u"your_username" 28 | passwd = u"your_password" 29 | 30 | 31 | """网址""" 32 | #我们学校强智选课URL 33 | select_url = "http://jw.sdufe.edu.cn/jsxsd/xsxk/xsxk_index?jx0502zbid=B07463ACED2349FD9FCFF81C582AC754" 34 | #强智登录URL 35 | login_url = "http://jw.sdufe.edu.cn/" 36 | 37 | 38 | def __init__(self): 39 | print("Welcome To Use The Tool") 40 | 41 | #登录模块 42 | def login(self): 43 | proxy.new_har() 44 | self.driver.visit(self.login_url) 45 | #填充密码 46 | self.driver.fill("userAccount",self.username) 47 | #sleep(1) 48 | self.driver.fill("userPassword",self.passwd) 49 | print("等待验证码,自行输入....") 50 | while True: 51 | if self.driver.url != self.initmy_url: 52 | sleep(1) 53 | else : 54 | break 55 | #抢课成功,利用twilio发送短信 56 | def send_message(): 57 | account_sid="your_sid" 58 | auth_token="your_auth_totken" 59 | client=Client(account_sid,auth_token) 60 | 61 | client.messages.create( 62 | body=u" 抢课成功,请登录查看 ",to="+86你注册twilio时手机号",from_="+twilio分配给你的手机号") 63 | 64 | #登录进入,开始抢课 65 | def start(self): 66 | self.driver = Browser(driver_name='chrome') 67 | self.driver.driver.set_window_size(1400,1000) 68 | self.login() 69 | self.driver.visit(self.select_url) 70 | #选择你想抢课的种类,名字或教学方式 71 | self.driver.find_by_text(u'公选课选课').click() 72 | class_name=u"网络授课" 73 | 74 | #利用iframe表格找到想选的课的选课按钮,然后点击 75 | #循环点击所有要抢的课的选课id,当抢课成功发送短信通知 76 | if self.driver.find_by_id('mainFrame'): 77 | with self.driver.get_iframe('mainFrame') as frame: 78 | b=frame.find_by_name("skls") 79 | b.fill(class_name) 80 | frame.find_by_value(u"查询").click() 81 | #要抢课的id列表 82 | list=['div_201820192012792','div_201820192012796','div_201820192012805','div_201820192012823', 83 | 'div_201820192012827','div_201820192012830','div_201820192012807', 84 | 'div_201820192012813','div_201820192012815','div_201820192012820'] 85 | #循环抢课,提示抢课成功后发送手机短信通知 86 | A=False 87 | while A==False: 88 | for i in range(len(list)): 89 | frame.find_by_id(list[i]).click() 90 | with frame.get_alert() as alert: 91 | alert.accept() 92 | if alert.text=="选课失败:此课堂选课人数已满!": 93 | alert.accept() 94 | continue 95 | elif alert.text=="选课成功": 96 | alert.accept() 97 | A=True 98 | print('抢课成功') 99 | self.send_message() 100 | break 101 | else: 102 | alert.accept() 103 | continue 104 | 105 | 106 | if __name__=="__main__": 107 | train = HuoChe() 108 | train.start() --------------------------------------------------------------------------------