用selenium编的挂机脚本,可能里面有点小BUG,但是程序总体能跑起来,满足挂分需求。 无加速功能,只能挂机!!!! 时间比较短,代码比较粗糙
代码语言:javascript复制import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
options = Options()
options.add_argument('–-incognito')
options.add_argument('--disable-infobars')
options.add_argument('--start-maximized')
options.add_argument("--no-sandbox")
options.add_argument("--disable-gpu") # 防止崩溃,规避bug
browser = webdriver.Chrome(options=options)
browser.implicitly_wait(30)
代码语言:javascript复制def login():
"""
登录
"""
browser.get("https://uat1.cqrspx.cn/portal/login")
if browser.find_element(By.ID, 'userName'): #用户名
browser.find_element(By.ID, 'userName').send_keys("")
if browser.find_element(By.ID, 'passWord'): # 密码
browser.find_element(By.ID, 'passWord').send_keys("")
input("登录成功后继续...")
代码语言:javascript复制def courselearning():
"""
课程学习
"""
browser.find_element(By.XPATH, '//*[@id="image-style-1-1670463052660613113120"]/div[2]/div[3]/div/div[1]/div/div/div').click()
windows = browser.window_handles
browser.switch_to.window(windows[-1])
browser.find_element(By.XPATH, '//*[@id="searchBar"]/section/div/div[2]/section/div[2]/section[1]/div/section[1]/img').click()
while True:
time.sleep(3)
progress = browser.find_element(By.CLASS_NAME, 'progress-text').text
print(f'当前学习进度【{progress}】')
if progress == '100%':
break
print('学习完毕')
browser.find_element(By.XPATH, '//*[@id="searchBar"]/section/div/div[4]/div/div[1]/div/div[3]').click() #切换未完成课程
course = browser.find_element(By.XPATH, '//*[@id="pane-MUST"]/div/div/div[1]/div/div[1]') # 顺序学习
course_name = course.text
print(f'正在学习:{course_name}')
course.click()
new_window = browser.window_handles
browser.switch_to.window(new_window[-1])
browser.switch_to.frame('aliPlayerFrame')
chapters = browser.find_elements(By.CLASS_NAME, 'first-line')
print(f'共有{len(chapters)}节')
i = 1
for chapter in chapters:
print(f'开始学习第{i}节')
i = 1
try:
if chapter.find_element(By.CLASS_NAME, 'finish-tig'): # 判断小节学习状态
print('已完成')
continue
except:
pass
try:
chapter.click() # 播放未学习小节
except:
break
time.sleep(10)
current_time = browser.find_element(By.CLASS_NAME, 'current-time').text # 当前学习进度
end_time = browser.find_element(By.CLASS_NAME, 'duration').text # 获取课程总时间
if len(current_time) == 5: # 时间格式转换成秒
current = int(current_time[0:2]) * 60 int(current_time[3:5])
else:
current = int(current_time[0:2]) * 60 * 60 (int(current_time[3:5]) * 60) int(current_time[6:8])
if len(end_time) == 5:
end = int(end_time[0:2]) * 60 int(end_time[3:5])
else:
end = int(end_time[0:2]) * 60 * 60 (int(end_time[3:5]) * 60) int(end_time[6:8])
wait_time = end - current # 计算播放时长并拆分每10分钟刷新一次
print(f'时长:{wait_time}秒')
rg = wait_time // 600
# print(f'刷新:{rg}次')
yu = wait_time % 600
for i in range(rg):
time.sleep(598)
browser.refresh() # 刷新网页防止验证
browser.switch_to.frame('aliPlayerFrame')
time.sleep(3)
browser.find_element(By.CLASS_NAME, 'outter').click()
try:
if chapter.find_element(By.CLASS_NAME, 'finish-tig'): # 判断小节学习状态
print('已完成')
continue
except:
pass
time.sleep(yu)
browser.close() # 学习完成,关闭页面
browser.switch_to.window(windows[-1])