Skip to content

Latest commit

 

History

12 Commits

Folders and files

Repository files navigation

Amazon Captcha Solver for Python requests, No Browser (CapMonster Cloud)

tests License: MIT Python 3.9+ requests

A runnable Amazon captcha solver in Python: it detects Amazon's "Enter the characters you see below" page, reads the captcha image and submits the answer using requests and the ImageToText task of the official CapMonster Cloud image captcha solver Python SDK. No browser is needed.

What this example does

  1. Opens an Amazon URL with a requests.Session; by default the captcha check page amazon.com/errors/validateCaptcha.
  2. Detects the captcha form and collects the image URL, hidden fields and the name of the answer input.
  3. Downloads the image in the same session and recognizes it with ImageToTextRequest.
  4. Sends the answer to validateCaptcha and repeats up to three times if a new captcha appears.

Requirements

Quick start

git clone https://github.com/CapMonsterCloud/python-amazon-captcha-solver.git
cd python-amazon-captcha-solver
pip install -r requirements.txt

export CAPMONSTER_API_KEY=your_key        # Windows: set CAPMONSTER_API_KEY=your_key
python examples/solve_amazon_captcha.py
python examples/solve_amazon_captcha.py --url https://www.amazon.com/dp/B000000000 --attempts 5

Tests (offline, with a saved captcha page):

pytest -q

How it works

  • Detect, then parse. is_captcha_page() looks for the validateCaptcha form and the captchacharacters input, so normal product pages pass through untouched. parse_captcha_page() uses only the standard html.parser.
  • Hidden fields are mandatory. The form carries amzn and amzn-r values that link the answer to this specific captcha. They are sent back together with the answer in field-keywords.
  • Same session for page and image. The image is downloaded with the cookies of the page request; a fresh request would get a different captcha.
  • Clean the answer. Amazon uses Latin letters only, so clean_answer() uppercases the result and drops spaces, digits and punctuation that OCR sometimes adds.
  • Retry loop. Amazon may show another captcha after a correct answer; the script checks the response page and repeats.

ImageToText basics

  • The task takes a picture of the captcha and returns the recognized characters as text.
  • Send only the captcha image itself. The SDK takes the raw image bytes and encodes them for you.
  • Each captcha is solved separately: when Amazon shows a new image, download it again in the same session and send a new request.

Common errors

Symptom Cause and fix
no captcha on the page Amazon did not ask for a captcha in this session. Nothing to solve, the cookies can be reused.
ValueError: Amazon captcha form not found Amazon showed a different page (sign-in, 503 dog page). Save the HTML and check which form it contains.
captcha is still shown after all attempts The session looks automated: add realistic headers, slow down, keep cookies, or use a proxy you are permitted to use.
Answer looks right but is rejected The image was downloaded outside the session or the hidden fields were dropped. Keep one Session for all requests.
[ERROR_ZERO_BALANCE] / [ERROR_KEY_DOES_NOT_EXIST] Top up the balance or check the API key.

Get an API key

This example needs a CapMonster Cloud account and API key. Register and get the key on the image captcha recognition 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

Automated access to Amazon is governed by Amazon's Conditions of Use. Use this example only where you have permission, for example for monitoring your own listings, and never for unauthorized collection of data. Keep your API key private.

Links


Amazon is a trademark of Amazon.com, Inc. or its affiliates. CapMonster Cloud is not affiliated with or endorsed by Amazon.