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

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

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','大学','201984110','j3725680','1')
  • 写回答

1条回答 默认 最新

  • Profits pouring in f 2023-07-11 22:23
    关注

    我的测试结果是 网页打开很好

    就是你有两个位置报错

    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','大学', '201984110', 'j3725680', '1')
    
    driver.find_element_by_xpath('//*[@id="qStudentID"]').click()
    

    报错为: AttributeError: 'WebDriver' object has no attribute 'find_element_by_xpath' 翻译就是 AttributeError:“WebDriver”对象没有属性“find_element_by_xpath”

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?