为了账号安全,请及时绑定邮箱和手机立即绑定

使用selenium webdriver时出现超时问题

使用selenium webdriver时出现超时问题

HUWWW 2023-07-11 15:29:54
这是我的 python 脚本:#!/usr/bin/python3# -*- coding: utf&shy;-8 &shy;-*-from selenium import webdriverfrom selenium.webdriver.chrome.options import Optionsfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support import expected_conditions as ECimport osoptions = Options()options.headless = Trueoptions.add_argument("window-size=1400,800")options.add_argument("--no-sandbox")options.add_argument("--disable-gpu")options.add_argument("start-maximized")options.add_argument("enable-automation")options.add_argument("--disable-infobars")options.add_argument("--disable-dev-shm-usage")driver = webdriver.Chrome(options=options)driver.get('https://paris-sportifs.pmu.fr/pari/sport/25/football')odds = [my_elem.text for my_elem in WebDriverWait(driver, 10).until(EC.visibility_of_all_elements_located((By.XPATH, '//a[contains(@href, "#")]')))]print(odds, '\n')driver.close()driver.quit()输出给我的是:Traceback (most recent call last):  File "./azerty.py", line 31, in <module>    odds = [my_elem.text for my_elem in WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located((By.XPATH, '/-a[contains(@href, "#")]')))]  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/support/wait.py", line 80, in until    raise TimeoutException(message, screen, stacktrace)selenium.common.exceptions.TimeoutException: Message: 该脚本可以与其他网页完美运行,但在本例中则不然。一些帮助,谢谢
查看完整描述

1 回答

?
哈士奇WWW

TA贡献1799条经验 获得超6个赞

请测试这段代码;请增加等待时间并使用 EC.presence_of_all_elements_ located 。


from selenium.webdriver.common.by import By

from selenium.webdriver.support import expected_conditions as EC

import os


options = Options()

options.headless = True

options.add_argument("window-size=1400,800")

options.add_argument("--no-sandbox")

options.add_argument("--disable-gpu")

options.add_argument("start-maximized")

options.add_argument("enable-automation")

options.add_argument("--disable-infobars")

options.add_argument("--disable-dev-shm-usage")


driver = webdriver.Chrome(options=options)


driver.get('https://paris-sportifs.pmu.fr/pari/sport/25/football')


odds = [my_elem.text for my_elem in WebDriverWait(driver, 50).until(EC.presence_of_all_elements_located((By.XPATH, '//a[contains(@href, "#")]')))]


print(odds, '\n')


查看完整回答
反对 回复 2023-07-11
  • 1 回答
  • 0 关注
  • 137 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信