啊搜 2020-12-05 10:59 采纳率: 40%
浏览 103

python用selenium打开网址显示whitelabel error page

我在写一个关于智慧树刷课的脚本

打开课程视频所在的链接会出现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','郑州大学','201984170410','jcq13043725680','1')


这个是我换成另外一个地址后,可以避免white报错,但是找不到课程的标签

这是为啥捏,python小白,请多包涵

  • 写回答

1条回答 默认 最新

  • 关注

    应该是网页把selenium屏蔽掉了
    我在写selenium时也有类似的情况
    你可以查一查“selenium反反爬”

    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突