Skip to content
CaptchaSonic

Selenium 연동

Selenium + CaptchaSonic

Selenium WebDriver 자동화 프로젝트를 위한 Python 중심의 캡차 해결입니다.

npm

빠른 설치

pip install captchasonic selenium

01

가져오기 및 설정

Selenium WebDriver와 CaptchaSonic Python SDK를 설정하세요.

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

대상으로 이동

브라우저를 실행하고 캡차가 있는 페이지로 이동하세요.

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 추출 후 해결

캡차 매개변수를 가져와 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

삽입 후 제출

해결 토큰을 적용하고 폼을 제출하세요.

# 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

관련 자료

자동화할 준비가 되셨나요?

API 키를 받고 몇 분 안에 캡차 해결을 시작하세요. $0.50 보너스 크레딧이 무료로 포함됩니다.

API 키 받기