Answer the question
In order to leave comments, you need to log in
How to fix an error when clicking on a website?
Good afternoon everyone. There is a Python script that parses this page:
https://www.flashscore.ru/
Clicks on each match and displays the link and date of each match.
Since clicking on a match opens a new browser, the code says to return to the previous window every time.
The code:
import time
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from bs4 import BeautifulSoup
driver = webdriver.Chrome(executable_path="C:\\Users\\iljal\\PycharmProjects\\parsingg\\chromedriver") # здесь указать путь к chromedriver он обычно в той же папке где и Ваш проект
driver.get('https://www.flashscore.ru/')
time.sleep(3) # C:\Users\iljal\PycharmProjects\parsingg\chromedriver
arr = driver.find_elements_by_css_selector(
".event__match.event__match--scheduled.event__match--oneLine"
)
# optional (if you are not satisfied with the download speed)
driver.set_page_load_timeout(0.5)
for channel in arr:
try:
channel.click()
except TimeoutException:
print("data not received. need more time in driver.set_page_load_timeout")
continue
driver.switch_to.window(driver.window_handles[arr.index(channel)+1])
html = driver.page_source
soup = BeautifulSoup(html, 'lxml')
almost_time = soup.find('div', class_='description__time mstat-date').get_text(strip=True)
res_time = almost_time.split()
time = res_time[-1]
link = driver.current_url
print(link)
print(time)
driver.switch_to.window(driver.window_handles[0])
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <div id="g_1_GzZFvoYt" title="Подробности матча!" class="event__match event__match--scheduled event__match--last event__match--oneLine">...</div> is not clickable at point (531, 814). Other element would receive the click: <p id="onetrust-policy-text">...</p>
(Session info: chrome=83.0.4103.97)
Answer the question
In order to leave comments, you need to log in
Some elements are not immediately available, so you need to set up an implicit wait.
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
driver = webdriver.Firefox()
driver.get("http://somedomain/url_that_delays_loading")
try:
element = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, "myDynamicElement"))
)
finally:
driver.quit()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question