如何使用Selenium WebDriver获取数据

问题描述

您好,我正在尝试提取此网页的几率:https://sport.genybet.fr/

这是我的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 time
import numpy as np
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://sport.genybet.fr/')

#GENYBET
odds = [my_elem.text for my_elem in webdriverwait(driver,50).until(EC.presence_of_all_elements_located((By.XPATH,'//div[contains(@class,"snc-odd-value-position snc-bet-avoid-click")]')))]

print(odds,'\n')

driver.close()
driver.quit()

输出使我知道:

Traceback (most recent call last):
  File "./azerty.py",line 28,in <module>
    odds = [my_elem.text for my_elem in webdriverwait(driver,80).until(EC.presence_of_all_elements_located((By.XPATH,"snc-odd-value-position snc-bet-avoid-click")]')))]
  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: 

此脚本可以与其他网页完美运行,但在这种情况下则不能。一些帮助,谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)