Issue
I'm trying to gather some information from transfermarkt with a scraper, but when I open the page with a bot I always get a huge prompt to accept cookies. I've tried finding the element for the accept button by copying the full xpath, copying the relative xpath, and using '//button[@title="ACCEPTEER ALLE"]', but it can never find the element. I've also tried using the wait until method, but that always led to time out errors because it still couldn't find it, and the page loads quickly. Does anyone know what's wrong?
This is the button:
<button title="ACCEPTEER ALLE" class="message-component message-button no-children focusable sp_choice_type_11 last-focusable-el" style="padding: 10px 15px; margin: 5px 10px; border-width: 2px; border-color: rgb(92, 166, 255); border-radius: 4px; border-style: solid; font-size: 14px; font-weight: 400; color: rgb(255, 255, 255); font-family: verdana, geneva, sans-serif; width: 225px; background: rgb(0, 25, 63);">ACCEPTEER ALLE</button>
This is my code:
league = "Primera DivisiĆ³n"
url = "https://www.transfermarkt.nl/schnellsuche/ergebnis/schnellsuche?query={}".format(league)
browser = webdriver.Chrome()
browser.get(url)
sleep(10)
button = browser.find_element(By.XPATH, '//button[@title="ACCEPTEER ALLE"]')
button.click()
Solution
It is inside an iframe, try the below code, its working:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it(driver.find_element(By.CSS_SELECTOR, "iframe#sp_message_iframe_575848")))
driver.find_element(By.XPATH,".//*[@title='ACCEPTEER ALLE']").click()
Answered By - AbiSaran
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.