Solve CAPTCHAs in Crawl4AI crawls with DeathByCaptcha

Solve CAPTCHAs in Crawl4AI crawls with DeathByCaptcha

Posted on 2026-12-04 | 5 min read | Category: captcha-automation | By DeathByCaptcha Engineering Team

CAPTCHA Automation


Solve CAPTCHAs in Crawl4AI crawls with DeathByCaptcha

A Crawl4AI crawl that stops at a protected form is not a failed crawl, it is a crawl that never reached the data. The fix is a navigation hook that asks DeathByCaptcha for the answer and hands it to the page before the extraction strategy reads anything.

Where the solve happens

Crawl4AI runs hooks around the navigation, and its own documentation puts verification waits in after_goto: the page is loaded and the widget, if there is one, is in the DOM. That is the whole design of this example —

  • the on_page_context_created hook blocks images, styles and fonts through route filtering: the run does not fetch what the solve does not need, and the challenge script still does;
  • the after_goto hook detects the widget, reads its data-sitekey, asks for a token, writes it into the page, submits and waits for the success state;
  • the extraction strategy turns the result into structured JSON.

The solve runs in the worker, never in the browser: the credentials never reach the page and the token is returned as a value, so it stays out of the log. Nothing is published on PyPI. The example is a folder you copy.

Files

File What it is
examples/crawl4ai/solver.py the solvers: plain functions over the official client, testable without a browser
examples/crawl4ai/crawler.py the Crawl4AI cookbook: hooks, the token walk and a CSS extraction strategy
examples/crawl4ai/README.md setup, hooks and limits

The hooks

Hook What it does
on_page_context_created route blocking — no images, styles or fonts
after_goto the CAPTCHA walk: detect #recaptcha-demo, read data-sitekey, solve, inject, submit, wait
extraction strategy JsonCssExtractionStrategy reads the success page as JSON

The post-navigation hook in full:

async def solve_challenge(page, context, url, response, **kwargs):
    """The post-navigation hook: detect, solve, hand the token over,
    submit and wait for the success state."""
    widget = await page.query_selector("#recaptcha-demo")
    if widget is None:
        # No challenge on this page: nothing to solve, keep crawling.
        return page

    sitekey = await widget.get_attribute("data-sitekey")
    token = SOLVED.get(url)

    if token is None:
        print(f"Solving the challenge for {url}")
        # The client blocks while it polls: keep it off the event
        # loop so the crawler keeps serving the browser.
        token = await asyncio.to_thread(dbc.solve_recaptcha_v2, sitekey, url)
        SOLVED[url] = token

    await page.evaluate(INJECT_TOKEN, token)
    await page.click("#recaptcha-demo-submit")
    # The submit navigates: wait for the success page before the
    # crawler takes its snapshot, or the result is the form again.
    await page.wait_for_selector(".recaptcha-success", timeout=30000)
    LAST_HTML[url] = await page.content()
    print("Token injected, form submitted")
    return page

The official Python client is synchronous: a solve inside the hook would freeze the crawler's event loop for up to two minutes while the browser waits. asyncio.to_thread keeps both running.

Setup

pip install deathbycaptcha-official
pip install -r examples/crawl4ai/requirements.txt
crawl4ai-setup                      # installs the browser, once

export DBC_USERNAME=your_username
export DBC_PASSWORD=your_password
# or: export DBC_AUTHTOKEN=your_authtoken

The example needs Python 3.10 or newer (Crawl4AI's own requirement).

Run

python examples/crawl4ai/crawler.py

The tiny page that looks like a block

This is the part that cost the most and readers will hit it too. The walk works — solve, inject, submit, the success page arrives, the extraction returns

[{"success": "Verification Success... Hooray!"}]

— and the crawl still comes back success=False:

Error: Blocked by anti-bot protection: Structural:
minimal_text, no_content_elements (426 bytes, 31 chars visible)

The success page of Google's demo is a single line. Crawl4AI's anti-bot check reads a page that small as a block page — and its own documentation calls this a cheap false positive whose rescue is the fallback_fetch_function. The example returns the page the crawl actually produced, keyed by URL:

async def rescue_fetch(url):
    return LAST_HTML.get(url)

A URL the crawl never produced returns nothing, so a real block still fails the way it should.

The two balance guards

  • One token per URL. The solved map is keyed by page: a retried run re-injects the token it already bought instead of paying for the same solve twice.
  • The example never retries silently. arun returns a failed result and the script raises: a failed solve must not burn the balance on attempts nobody sees.

The LLM half of the pipeline

Crawl4AI is built for AI extraction: this example ships the CSS strategy because it needs no API key and runs in the tests. The LLM strategies slot into the same CrawlerRunConfig(extraction_strategy=...) position — see the LLM strategies of the Crawl4AI documentation when the page needs reasoning instead of selectors. The CAPTCHA walk does not change: the hook still hands the page over solved, and the strategy still reads it afterwards.

What the crawl does

  1. Visits Google's reCAPTCHA demo — the vendor's own page, not a third party's production site.
  2. The on_page_context_created hook blocks the static assets.
  3. The after_goto hook reads the data-sitekey from the page instead of typing it in and asks for a token.
  4. It writes the token into #g-recaptcha-response and calls the widget's callback — the same walk as the Selenium, Playwright, Crawlee, Puppeteer, Cypress and WebdriverIO samples across the two clients.
  5. Submits, waits for .recaptcha-success and lets the CSS strategy extract the result as JSON.

The rule that catches people out

A token answer is valid only from the exit IP that solved it. The solve runs on the machine that runs the crawl, so a solve and the request it is pasted into leave from the same machine — unless your crawl leaves through a proxy, in which case pass the same proxy and proxytype in the parameters.

Limits

  • QA on your own pages. These crawls are for flows you are allowed to automate — staging, a demo, a page you own. See RESPONSIBLE_USE.md.
  • reCAPTCHA v3 needs the action and the min_score the site expects; a mismatch is a token the site refuses.
  • The sandbox: Crawl4AI launches Chromium with it on, which a CI container rarely supports. The example turns it off with extra_args=["--no-sandbox"]; delete the line where your runner has a working sandbox.
  • Never print the token: the solvers return it as a value and nothing else should echo it.

Tests

python -m pytest tests/test_crawl4ai_solver.py -v        # no network
DBC_TEST_USERNAME=... DBC_TEST_PASSWORD=... python -m pytest tests/test_crawl4ai_integration.py -v

The unit tests replace the client with a mock. The integration test runs the real crawler against the live API, checks that it extracted the verification and fails if anything it prints looks like a token. It skips itself when Crawl4AI or the credentials are not in the environment, and it runs in the continuous integration of the repository on every push.

Next steps

  • Example: https://github.com/deathbycaptcha/deathbycaptcha-api-client-python
  • API documentation: https://deathbycaptcha.com/api

Common pitfalls

  • Using a CAPTCHA solving service for illegitimate purposes instead of legitimate automation and testing.
  • Hard-coding credentials or API keys in client-side code that users can inspect.
  • Sending the wrong CAPTCHA type parameter, which returns incorrect or empty responses.
  • Failing to poll for the solution status and not handling timeouts gracefully.
  • Scaling automation without monitoring error rates, response times, and CAPTCHA type coverage.
DBC
Written by DeathByCaptcha Engineering Team
DeathByCaptcha engineers build and operate the CAPTCHA solving technology behind this site. Articles are written by our technical team and checked for accuracy before publishing.
Reviewed by DeathByCaptcha Editorial Team

Get your API key — start solving

Free to try · No credit card · Python, Node.js, Java, C# SDKs

Get your API key


Status: OK

Servers are fully operational with faster than average response time.
  • Average solving time
  • 4 seconds - Normal CAPTCHAs (1 min. ago)
  • 5 seconds - reCAPTCHA V2, V3 (1 min. ago)
  • 13 seconds - others (1 min. ago)
Chrome and Firefox logos
Browser extensions available

Updates

  1. Dec 01: RESOLVED -The temporary technical issue affecting account registration emails and other automated messages has been resolved, and normal email delivery has been restored. We apologize for any inconvenience this may have caused and appreciate your patience and understanding!
  2. Nov 19: RESOLVED - Crypto payments are now fully operational again through the Hekelet payment processor.
  3. May 13: Crypto payments got better! You can now purchase your CAPTCHAs using cryptocurrency through the Hekelet payment processor at https://deathbycaptcha.com/user-pay and receive an extra 20% FREE CAPTCHA credit with every package purchased this way.

  4. Previous updates…

Support

Our system is designed to be completely user-friendly and easy-to-use. Should you have any trouble with it, simply email us at DBC technical support emailcom, and a support agent will get back to you as soon as possible.

Live Support

Available Monday to Friday (10am to 4pm EST) Live support image. Link to live support page