python-selenium
前言
抢课之际,拼不过手速,好吧我直接上脚本好吧
😁
selenium实现自动化选课
selenium这一自动化测试的特性嘿嘿嘿,拿它来抢课岂不乐哉,话不多说直接开撸
✌
其实特别简单,就那两三步
1.输入账号密码登录,有验证码识别直接用验证码识别平台,那点钱咱就是说不缺好吧
2.就直接用selenium实现点击点击点击。。。。然后就抢完啦!
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
import requests
from hashlib import md5
import time
class Chaojiying_Client(object): # 超级鹰类
def __init__(self, username, password, soft_id):
self.username = username
password = password.encode('utf8')
self.password = md5(password).hexdigest()
self.soft_id = soft_id
self.base_params = {
'user': self.username,
'pass2': self.password,
'softid': self.soft_id,
}
self.headers = {
'Connection': 'Keep-Alive',
'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)',
}
def PostPic(self, im, codetype):
"""
im: 图片字节
codetype: 题目类型 参考 http://www.chaojiying.com/price.html
"""
params = {
'codetype': codetype,
}
params.update(self.base_params)
files = {
'userfile': ('ccc.jpg', im)}
r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, files=files, headers=self.headers)
return r.json()
def PostPic_base64(self, base64_str, codetype):
"""
im: 图片字节
codetype: 题目类型 参考 http://www.chaojiying.com/price.html
"""
params = {
'codetype': codetype,
'file_base64':base64_str
}
params.update(self.base_params)
r = requests.post('http://upload.chaojiying.net/Upload/Processing.php', data=params, headers=self.headers)
return r.json()
def ReportError(self, im_id):
"""
im_id:报错题目的图片ID
"""
params = {
'id': im_id,
}
params.update(self.base_params)
r = requests.post('http://upload.chaojiying.net/Upload/ReportError.php', data=params, headers=self.headers)
return r.json()
web = Chrome()
# 打开教务在线
web.get('http://xk1.cqupt.edu.cn/') # 摊牌了,我就是cqupt的
# 输入信息登录
web.find_element(By.XPATH,'//*[@id="loginForm"]/input[1]').send_keys('**********') # 账号
web.find_element(By.XPATH,'//*[@id="loginForm"]/input[2]').send_keys('********') # 密码
img = web.find_element(By.XPATH,'//*[@id="vCodePic"]').screenshot_as_png
# 使用超级鹰破解验证码
chaojiying = Chaojiying_Client('*******','****', '******') # 信息不暴露(doge
code=chaojiying.PostPic(img,1902)['pic_str']
star = time.time() # 记录一下咱们速度好吧
web.find_element(By.XPATH,'//*[@id="vCode"]').send_keys(code)
web.find_element(By.XPATH,'//*[@id="submitButton"]').click() # 进入网站
while 1: #防止太快了页面没出来就点,点个皮皮虾
try:
web.find_element(By.XPATH,'//*[@id="sidebar"]/ul/li[1]/ul/li[3]/a').click()
break
except:
print('页面未加载')
while 1:
try:
web.find_element(By.XPATH,'//*[@id="dxKchTable"]/tbody/tr[8]/td[5]').click()
break
except:
print("页面未加载")
end = time.time()
t = end-star
print(f'用时{t}')