Skip to content

Latest commit

 

History

12 Commits

Folders and files

Repository files navigation

reCAPTCHA v2 Solver for Python requests, No Browser (CapMonster Cloud)

tests License: MIT Python 3.9+ requests

A small Python reCAPTCHA v2 solver that works without Selenium or a headless browser: it reads the form with requests, gets a token from the official CapMonster Cloud reCAPTCHA v2 solver Python SDK and submits the form over HTTP. Useful for lightweight scrapers and API-style integrations on sites you are allowed to automate.

What this example does

  1. Downloads the page with a requests.Session and a fixed desktop User-Agent.
  2. Parses the form that contains the reCAPTCHA v2 widget: sitekey, action, method and hidden fields.
  3. Asks CapMonster Cloud for a token with RecaptchaV2Request, sending the same User-Agent.
  4. Posts the form back with g-recaptcha-response, keeping cookies from the first request.

The default target is the public demo page lessons.zennolab.com.

Requirements

  • Python 3.9+
  • A CapMonster Cloud API key (see Get an API key)
  • No browser and no WebDriver

Quick start

git clone https://github.com/CapMonsterCloud/python-requests-recaptcha-v2-solver.git
cd python-requests-recaptcha-v2-solver
pip install -r requirements.txt

export CAPMONSTER_API_KEY=your_key        # Windows: set CAPMONSTER_API_KEY=your_key
python examples/solve_recaptcha_v2_requests.py
python examples/solve_recaptcha_v2_requests.py --url https://your-site.example/form --field email=me@example.com

Tests (offline, no API key):

pytest -q

How it works

  • The form is the contract. parse_recaptcha_form() uses only the standard html.parser. It picks the <form> that actually contains the widget (pages often have a search form first), resolves a relative action against the final page URL after redirects and collects hidden inputs such as CSRF tokens.
  • Sitekey fallbacks. If there is no data-sitekey attribute, the parser looks for a 40-character k= value in an embedded anchor URL.
  • Same session end to end. Cookies from the GET request and the Referer header go with the POST. Many backends reject a valid token if the session that loaded the form is not the one that submits it.
  • Payload instead of DOM. build_payload() adds g-recaptcha-response exactly as the browser widget would post it, so the server cannot tell the difference between the two flows.

reCAPTCHA v2 token basics

  • The token is a g-recaptcha-response string. Send it in the form payload under that name.
  • reCAPTCHA v2 tokens are single-use and short-lived. Request a new token for every submission and submit right away.
  • Pass the same page URL and sitekey that the browser used, otherwise the token can be rejected on validation.

Common errors

Symptom Cause and fix
ValueError: No reCAPTCHA v2 sitekey found The widget is injected by JavaScript after load. Find the sitekey in DevTools and use the browser examples, or call the site's API directly.
Submission returns the form again A required field is missing. Add it with --field name=value or check the hidden inputs the page expects.
HTTP 403 on the first GET The site blocks plain HTTP clients. Send the headers a browser sends or use a proxy you are allowed to use.
Token accepted in a browser but not here The server binds the token to cookies or IP. Keep one Session and send the solve through the same proxy.
[ERROR_KEY_DOES_NOT_EXIST] / [ERROR_ZERO_BALANCE] Wrong API key or empty balance.

Get an API key

This example needs a CapMonster Cloud account and API key. Register and get the key on the reCAPTCHA v2 solver page. There you will also find pricing and the API description. New users can ask support for a $0.10 test balance after registering.

Responsible use

Use this example only on websites you own or have explicit permission to automate. Respect the website's terms of service and applicable laws. Never commit your API key.

Links


reCAPTCHA is a trademark of Google LLC. CapMonster Cloud is not affiliated with or endorsed by Google.