Python 使用selenium webdriver时出现超时问题

Python 使用selenium webdriver时出现超时问题,python,selenium-webdriver,extract,Python,Selenium Webdriver,Extract,您好,我正在尝试提取此网页的赔率: 以下是我的python脚本: #!/usr/bin/python3 # -*- coding: utf­-8 ­-*- from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common

您好,我正在尝试提取此网页的赔率:

以下是我的python脚本:

#!/usr/bin/python3
# -*- coding: utf­-8 ­-*-

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
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, 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: 
回溯(最近一次呼叫最后一次):
文件“/azerty.py”,第31行,在
赔率=[my_elem.text for my_elem in WebDriverWait(driver,10)。直到(EC.presence_of_all_element_located((By.XPATH,“/-a[contains(@href,“#”))]
文件“/usr/local/lib/python3.8/dist-packages/selenium/webdriver/support/wait.py”,第80行,直到
引发TimeoutException(消息、屏幕、堆栈跟踪)
selenium.common.Exception.TimeoutException:消息:

此脚本可以与其他网页完美地运行,但在本例中并非如此。一些帮助,谢谢

请测试此代码;请增加等待时间并使用所有元素的EC.presence

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')

什么都没有改变你什么都没有是什么意思?对不起,这对我来说是个错误。它工作得很好。谢谢