我在写一个关于智慧树刷课的脚本
打开课程视频所在的链接会出现whitelabel error page
但是打开登陆的url不会出错
如何解决这个问题?
我本来想通过在登陆以后click()课程达到同样的目的
但是程序报错找不到标签
请问这是什么原因?我是新手,直接copy了课程title的xpath
from selenium import webdriver
import time
import re
import tkinter
from tkinter import messagebox
from selenium.webdriver.common.action_chains import ActionChains
# #在登陆界面需要填入的信息
# class task(url,school,account,pdw,max_lesson):
# def __init__(self):
# self.url=url#课程网址
# self.school=school#学校
# self.accout=account#账户
# self.pdw=pdw#密码
# self.max_lesson=max_lesson#最大课程数
#
#
# # #自动解决弹出问题
def window_tk():
try:
driver.find_element_by_xpath('//*[@id="app"]/div/div[7]/div[2]/div[1]/i').click()#关闭学前必读
except:
pass
try:
driver.find_element_by_class_name('el-dialog__headerbtn').click()#关闭智慧树警告
except:
pass
try:
anser=driver.find_element_by_xpath('//*[@id="app"]/div/div[7]/div/div[2]/div/div[1]/div/div/div[2]/div/p/span').text#回答问题
options=driver.find_element_by_class_name('topic-item')
for i in range(10):
if char(ord('A')+i)==anser:
options[i].click()
pass
driver.find_element_by_xpath('//*[@id="app"]/div/div[7]/div/div[3]/span/div').click()
driver.find_element_by_xpath('//*[@id="playButton"]').click()
except:
pass
def auto_study(url,school,account,pwd,max_lesson):
opt=webdriver.ChromeOptions()
opt.add_experimental_option('useAutomationExtension', False)#关闭“chrome正受到自动测试软件的控制”
opt.add_experimental_option('excludeSwitches', ['enable-automation'])
opt.add_experimental_option('detach',True)#不自动关闭浏览器
global driver
driver=webdriver.Chrome(options=opt)
try:
driver.get(url)
except:
return -1#尝试打开网址
time.sleep(2)
driver.find_element_by_xpath('//*[@id="qStudentID"]').click()
driver.find_element_by_xpath('//*[@id="quickSearch"]').send_keys(school)
driver.find_element_by_xpath('//*[@id="schoolListCode"]/li[3]').click()
driver.find_element_by_xpath('//*[@id="clCode"]').send_keys(account)
driver.find_element_by_xpath('//*[@id="clPassword"]').send_keys(pwd)
driver.find_element_by_xpath('//*[@id="f_sign_up"]/div[1]/span').click()
time.sleep(2)
# driver.find_element_by_xpath('//*[@id="sharingClassed"]/div[2]/ul/div/dl/dd/div/img').click()
for time_slip in range(int(1e9)):
window_tk()
try:
currenttime=driver.find_element_by_xpath('//*[@id="vjs_container"]/div[10]/div[4]/span[1]').text
duration=driver.find_element_by_xpath('//*[@id="vjs_container"]/div[10]/div[4]/span[2]').text
if currenttime==duration:
try:
driver.find_element_by_xpath('//*[@id="nextBtn"]').click()
max_lesson-=1
if(max_lesson==0):
return
except:
pass
except:
pass
auto_study('https://passport.zhihuishu.com/login?service=http%3A%2F%2Fstudyservice.zhihuishu.com%2Flogin%2Fgologin%3Ffromurl%3Dhttps%253A%252F%252Fstudyh5.zhihuishu.com%252FvideoStudy.html%2523%252FstudyVideo%253FrecruitAndCourseId%253D495b595e465241584c4c5b5f51','xx大学','2zzzzz70410','zzzzz725680','1')