您好,我正在尝试使用pyhton和硒webscrape网页。我试图从页面获取的信息是比赛信息/计分板。例如当前设置,玩家名称,每个玩家的积分。我不断收到TimeoutException。有人可以告诉我如何在下面检索此信息吗?是指向该页面示例的链接。
https://www.bovada.lv/sports/tennis/itf-men/chile-singles/a-tabilo-i-monzon-201811211325
下面是我的代码
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from bs4 import BeautifulSoup
driver = webdriver.Chrome()
driver.maximize_window()
wait = WebDriverWait(driver, 50)
small_wait = WebDriverWait(driver, 50)
driver.execute_script('window.open("https://www.bovada.lv/sports/tennis/itf-men/chile-singles/a-tabilo-i-monzon-201811211325","_self")')
#//*[@id="tracker__header"]
dat = []
try:
dat.append([wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="tracker__header"]/div/div[1]/div/div[2]'))).text])
except TimeoutException:
print('error')
driver.quit()
以下是我想从网站获得的信息
最佳答案
您需要切换到iframe才能获得价值:
driver.switch_to.frame(driver.find_element_by_css_selector('iframe[id^="iframe-tracker-"]'))
try:
dat.append(wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="tracker__header"]/div/div[1]/div/div[2]'))).text)
except TimeoutException:
print('error')
关于python - Python Selenium Webscrape,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53418867/