Skip to content
CaptchaSonic

Selenium Integration

Selenium + CaptchaSonic

Python-zentrierte Captcha-Lösung für Selenium-WebDriver-Automatisierungsprojekte.

npm

Schnellinstallation

pip install captchasonic selenium

01

Importieren und konfigurieren

Richten Sie Selenium WebDriver und das CaptchaSonic-Python-SDK ein.

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
from captchasonic import CaptchaSonic

# Solves over a native gRPC connection (no HTTP overhead)
client = CaptchaSonic("sonic_your_key_here")

02

Zum Ziel navigieren

Starten Sie den Browser und öffnen Sie die Seite mit dem Captcha.

driver = webdriver.Chrome()
driver.get("https://example.com/login")

# Wait for captcha to load
WebDriverWait(driver, 10).until(
    EC.presence_of_element_located(
        (By.CSS_SELECTOR, "iframe[src*='recaptcha']")
    )
)

03

Sitekey extrahieren und lösen

Lesen Sie die Captcha-Parameter aus und senden Sie sie an CaptchaSonic.

# Get the sitekey from the page
sitekey = driver.find_element(
    By.CSS_SELECTOR, "[data-sitekey]"
).get_attribute("data-sitekey")

# Solve with CaptchaSonic over gRPC
result = client.solve_recaptcha_v2_token(
    website_url=driver.current_url,
    website_key=sitekey,
)

token = result["solution"]["gRecaptchaResponse"]
print(f"Token: {token}")

04

Einfügen und absenden

Wenden Sie das Lösungs-Token an und senden Sie das Formular ab.

# Inject the token
driver.execute_script(f"""
    document.getElementById('g-recaptcha-response')
        .innerHTML = '{token}';
""")

# Submit the form
driver.find_element(By.CSS_SELECTOR, "button[type='submit']").click()

# Wait for page transition
WebDriverWait(driver, 10).until(
    EC.url_changes(driver.current_url))
print("Captcha bypassed successfully!")

Links

Verwandte Ressourcen

Bereit zur Automatisierung?

Holen Sie sich Ihren API-Schlüssel und lösen Sie Captchas in wenigen Minuten. Inklusive $0.50 Bonusguthaben.

API-Schlüssel abrufen