使用须知:环境请自己配置好,临时写的,比较简陋,出现问题概不负责,祝使用愉快
效果图:
(实测抢马原成功!但有封号封ip风险,尽管没有试过,请谨慎使用)
from selenium import webdriver
import time
from datetime import datetime
import win32api,win32con
"""
抢课脚本
author:Anthony
使用说明:此版本使用的是102.0.5005.115版本Chrome浏览器,请自行下载对应版本的ChromeDriver镜像,下载链接:https://registry.npmmirror.com/binary.html?path=chromedriver/&spm=a2c6h.24755359.0.0.6ae24dccdOiorE
使用前注意配置好环境和所需的资源包,需要自行修改账号和密码,以及所选课程,注意暂时不支持选择指定日期和老师,此程序只针对于该课程所有已满的情况,但是要改也不难,可以自行修改,祝使用愉快
"""
option=webdriver.ChromeOptions()
option.add_argument('headless')
# 无界面启动,也可以直接设置options.headless=True
def catch():
while 1:
try:
driver = webdriver.Chrome(options=option) #将括号里的内容去掉可以可视化执行窗口
driver.get('http://newjw.hdu.edu.cn')
driver.maximize_window()
driver.find_element_by_xpath('//*[@id="yhm"]').send_keys('1234') #账号
driver.find_element_by_xpath('//*[@id="mm"]').send_keys('1234') #密码(密码规则好像和数字杭电不太一样,具体可以点开上面链接看看)
driver.find_element_by_xpath('//*[@id="dl"]').click()
time.sleep(5)
for j in range(150):
status = []
driver.refresh()
driver.find_element_by_xpath('//*[@id="searchBox"]/div/div[1]/div/div/div/div/input').send_keys('马克思主义') #课程
driver.find_element_by_xpath('//*[@id="searchBox"]/div/div[1]/div/div/div/div/span/button[1]').click()
time.sleep(3)
for i in range(0,34): #有多少个课程可选这个34就换成对应数量,可以优化,懒得写
status.append(driver.find_element_by_xpath(f'/html/body/div[1]/div/div/div[5]/div/div[2]/div[1]/div[2]/table/tbody/tr[{i+1}]/td[21]').text)
print(status)
for i in range(34): #同上
if status[i] != '已满':
print('有余量!!!')
driver.find_element_by_xpath(f'/html/body/div[1]/div/div/div[5]/div/div[2]/div[1]/div[2]/table/tbody/tr[{i+1}]/td[24]/button').click()
win32api.MessageBox(0, "抢课成功", "抢课提示", win32con.MB_OK)
return
print('结束')
print(datetime.now())
except Exception as e:
print('出错')
time.sleep(10)
if __name__ == '__main__':
catch()



