Learn how to build a complete CAPTCHA automation workflow using Python, Selenium, and CaptchaKings API. This tutorial covers reCAPTCHA v2, v3, and hCaptcha.
Prerequisites
Install the required packages:
pip install selenium requests webdriver-managerComplete Python Script
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import requests
class CaptchaSolver:
def __init__(self, api_key):
self.api_key = api_key
def solve_recaptcha_v2(self, site_key, page_url):
# NOTE: reCAPTCHA support is planned at CaptchaKings.
# Planned flow: one synchronous POST per solve with your API key and
# the site parameters — the final endpoint and request format will be
# announced on the CaptchaKings changelog at launch.
# Live status: https://captchakings.com/supported-captchas
raise NotImplementedError("reCAPTCHA support is coming soon to CaptchaKings")
# Usage with Selenium
solver = CaptchaSolver("YOUR_API_KEY")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get("https://example.com/login")
# Get sitekey from page
sitekey = driver.find_element(By.CLASS_NAME, "g-recaptcha").get_attribute("data-sitekey")
# Solve captcha
token = solver.solve_recaptcha_v2(sitekey, driver.current_url)
# Inject token
driver.execute_script(f'document.getElementById("g-recaptcha-response").innerHTML = "{token}"')
# Submit form
driver.find_element(By.ID, "submit").click()Key Features
- Automatic sitekey extraction
- Planned flow: one synchronous POST per solve (see note in code)
- Token injection into hidden textarea
- Works with any reCAPTCHA v2 protected site