Skip to content

Wait for CAPTCHa #15

@jgarciab

Description

@jgarciab

Sometimes Google shows a CAPTCHA. Something like this would check and wait until manually solved.

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# Define a function to check if CAPTCHA is present on the page
def is_captcha_present(xpath_captcha)
):
    try:
        captcha_element = driver.find_element(By.XPATH, xpath_captcha]')  # Adjust this XPath to match the CAPTCHA container on your target website
        return captcha_element.is_displayed()
    except:
        return False

# Check if CAPTCHA is present
xpath_captcha = '//div[contains(@class, "captcha-container")
if is_captcha_present(xpath_captcha):
    print("CAPTCHA detected. Please solve it to proceed.")

    # Wait for the user to complete the CAPTCHA
    WebDriverWait(driver, 3600).until_not(EC.presence_of_element_located((By.XPATH, xpath_captcha)))  # Adjust this XPath to match the CAPTCHA container on your target website

    print("CAPTCHA solved successfully. Proceeding with scraping.")



Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions