我正在尝试抓取此页面:
https://www.ultimatetennisstatistics.com/tournamentEvent?tournamentEventId=4073
我想单击每个蓝色的统计图标(每场比赛都有一个)
这是我的代码:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
path="C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(path)
URL = "https://www.ultimatetennisstatistics.com/tournamentEvent?tournamentEventId=4073"
driver.get(URL)
driver.implicitly_wait(10)
cookies = driver.find_element_by_id("cookiesNotification")
cookies.click()
# Trying to click the cookies
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "matchStats-171140")))
element.click()
这是我得到的答案:
ElementClickInterceptedException: element click intercepted: Element <a...id="matchStats-171140" href="#" class="btn btn-info btn-xxs glyphicon glyphicon-stats" onclick="showMatchStats(171140, event, false)" title="Match Statistics"> </a> is not clickable at point (880, 566). Other element would receive the click: <div id="cookiesNotification" style="position: fixed; left: 0px; bottom: 0px; width: 100%; z-index: 100; text-align: center; background-color: indigo; color: wheat; opacity: 0.9; padding: 10px;">...</div>
我尝试单击cookie的按钮,但是没有用...
我想要的输出,例如通过点击决赛,应该看起来像this
有人可以帮助我吗?
谢谢
答案 0 :(得分:0)
您可以使用javascript执行程序单击“接受cookie”按钮:-
WebElement acceptCookieButton = driver.findElement(By.linkText("OK, I agree"));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", acceptCookieButton);
一旦Cookie被接受,您所有的网络元素都将可以点击。