CAPSOLVER
Blog
How to Solve Captcha in Puppeteer using CapSolver

How to Solve Captcha in Puppeteer using CapSolver

Logo of CapSolver

Sora Fujimoto

AI Solutions Architect

17-Jul-2023

How to Solve Captcha in Puppeteer using CapSolver

How to Solve Captcha in Puppeteer using CapSolver

🎯 Overview

This tutorial will guide you through the process of solving Google reCaptchas in Puppeteer using CapSolver.

CapSolver is a Captcha Solving Service that helps you solve Captchas.

We use AI-powered Captcha Solving Algorithms, which result in faster solving speed and significantly reduced costs, providing an excellent developer experience.

The goal will be to solve the captcha located at recaptcha-demo.appspot.com using CapSolver.

Captcha Form

During the tutorial, we will take the following steps to solve the above Captcha:

  1. Install the required dependencies.
  2. Find the site key of the Captcha Form.
  3. Set up CapSolver.
  4. Solve the captcha.

📦 Install Required Dependencies

To get started, we need to install the following dependencies for this tutorial:

  • capsolver-python: The official Python SDK for easy integration with the CapSolver API.
  • pyppeteer: pyppeteer is a Python port of Puppeteer.

Install these dependencies by running the following command:

Copy
python -m pip install pyppeteer capsolver-python

Now, Create a file named main.py where we will write the Python code for solving captchas.

bash Copy
touch main.py

🔑 Get Site Key of Captcha Form

The Site Key is a unique identifier provided by Google that uniquely identifies each Captcha.

To solve the Captcha, it is necessary to send the Site Key to CapSolver.

Let's find the Site Key of the Captcha Form by following these steps:

  1. Visit the Captcha Form.
Captcha Form
  1. Open Chrome Dev Tools by pressing Ctrl/Cmd + Shift + I.
  2. Go to the Elements tab and search for data-sitekey. Copy the attribute's value.
Site Key
  1. Store the Site Key in a secure place as it will be used in a later section when we submit the captcha to CapSolver.

🤖 Setup CapSolver

To solve captchas using CapSolver, you need to create a CapSolver account, add funds to your account, and obtain an API Key. Follow these steps to set up your CapSolver account:

  1. Sign up for a CapSolver account by visiting capsolver.com.
Sign Up
  1. Add funds to your CapSolver account using PayPal, Crypto Currencies, or other listed payment methods. Please note that the minimum deposit amount is $6, and additional taxes apply.
Add Funds
  1. Now, copy the API Key provided by CapSolver and store it securely for later usage.
Store API Key

💡 Solving the Captcha

Now, we will proceed to solving the captcha using CapSolver. The overall process involves three steps:

  1. Launching the browser and visiting the captcha page using pyppeteer.
  2. Solving the captcha using CapSolver.
  3. Submitting the captcha response.

Read the following Code Snippets to understand these steps.
Launching the browser and visiting the captcha page:

python Copy
# Launch the browser.
browser = await launch({'headless': False})

# Load the target page.
captcha_page_url = "https://recaptcha-demo.appspot.com/recaptcha-v2-checkbox.php"
page = await browser.newPage()
await page.goto(captcha_page_url)

Solving the captcha using CapSolver:

python Copy
# Solve the reCAPTCHA using CapSolver.
capsolver = RecaptchaV2Task("YOUR_API_KEY")

site_key = "6LfW6wATAAAAAHLqO2pb8bDBahxlMxNdo9g947u9"
task_id = capsolver.create_task(captcha_page_url, site_key)
result = capsolver.join_task_result(task_id)

# Get the solved reCAPTCHA code.
code = result.get("gRecaptchaResponse")

Setting the solved captcha on the form and submitting it:

python Copy
# Set the solved reCAPTCHA code on the form.
recaptcha_response_element = await page.querySelector('#g-recaptcha-response')
await page.evaluate(f'(element) => element.value = "{code}"', recaptcha_response_element)

# Submit the form.
submit_btn = await page.querySelector('button[type="submit"]')
await submit_btn.click()

🚀 Putting it all Together

Below is the complete code for the tutorial, which will solve the captcha using CapSolver.

python Copy
import asyncio
from pyppeteer import launch
from capsolver_python import RecaptchaV2Task

# Following code solves a reCAPTCHA v2 challenge using CapSolver.
async def main():
    # Launch Browser.
    browser = await launch({'headless': False})

    # Load the target page.
    captcha_page_url = "https://recaptcha-demo.appspot.com/recaptcha-v2-checkbox.php"
    page = await browser.newPage()
    await page.goto(captcha_page_url)

    # Solve the reCAPTCHA using CapSolver.
    print("Solving captcha")
    capsolver = RecaptchaV2Task("YOUR_API_KEY")

    site_key = "6LfW6wATAAAAAHLqO2pb8bDBahxlMxNdo9g947u9"
    task_id = capsolver.create_task(captcha_page_url, site_key)
    result = capsolver.join_task_result(task_id)

    # Get the solved reCAPTCHA code.
    code = result.get("gRecaptchaResponse")
    print(f"Successfully solved the reCAPTCHA. The solve code is {code}")

    # Set the solved reCAPTCHA code on the form.
    recaptcha_response_element = await page.querySelector('#g-recaptcha-response')
    await page.evaluate(f'(element) => element.value = "{code}"', recaptcha_response_element)

    # Submit the form.
    submit_btn = await page.querySelector('button[type="submit"]')
    await submit_btn.click()

    # Pause the execution so you can see the screen after submission before closing the driver
    input("Captcha Submission Successfull. Press enter to continue")

    # Close Browser.
    await browser.close()

if __name__ == "__main__":
    asyncio.get_event_loop().run_until_complete(main())

Paste the above code into your main.py file. Replace YOUR_API_KEY with your API Key and run the code.

You will observe that the captcha will be solved, and you will be greeted with a success page 🥳.

Solved Captcha Success Page

✅ Conclusion

Congratulations! You have successfully learned how to solve captchas using CapSolver. Here are the key learnings from this tutorial:

  • CapSolver offers a fast and cost-effective solution for captcha solving.
  • The general process to solve the captcha involves:
    • Creating an account on CapSolver and adding funds to it.
    • Finding the Site Key of the target captcha form.
    • Submitting the Site Key and Page URL to CapSolver to solve the captcha.
    • Setting the solved captcha response on the appropriate element and submitting the form.

Thank you for your time. 🙏 We wish you good luck on your automation journey! 🚀

🤔 FAQs

What is the Cost of Solving Captchas?

We employ AI-powered captcha solving algorithms instead of human solvers, resulting in significantly lower captcha solving costs. Hence, our rates are highly competitive in the market.

For example, the cost of solving Google v2/v3 captchas ranges from 0.8 to 1.

To learn more about our pricing in detail, we encourage you to visit our pricing page here.

I am successfully able to solve reCaptcha located at recaptcha-demo.appspot.com but when I try to solve anothet reCaptcha, it does not get solved. Why?

In this tutorial, we solved Google reCaptcha V2, but your target website is most likely using Google reCaptcha V3.

When solving Google reCaptcha V3, it is important to ensure that the IP address and user agent used to submit the captcha match the ones used to solve it.

Once you have residential proxies available, you can update the code as follows to solve the captcha successfully:

  • Use a proxy when launching Puppeteer.
python Copy
browser = await launch({'args': ['--proxy-server=ip:port'], 'headless': False})
  • Set the proxy and user agent after creating the proxy task as follows:
python Copy
capsolver = RecaptchaV2Task("YOUR_API_KEY")

capsolver.set_proxy(proxy_address='proxy_ip', proxy_port='proxy_port', proxy_login='user', proxy_password='password')

browser_useragent = browser.userAgent()
capsolver.set_user_agent(browser_useragent)

Compliance Disclaimer: The information provided on this blog is for informational purposes only. CapSolver is committed to compliance with all applicable laws and regulations. The use of the CapSolver network for illegal, fraudulent, or abusive activities is strictly prohibited and will be investigated. Our captcha-solving solutions enhance user experience while ensuring 100% compliance in helping solve captcha difficulties during public data crawling. We encourage responsible use of our services. For more information, please visit our Terms of Service and Privacy Policy.

More

The-Ultimate-CAPTCHA-Solver
Best Captcha Solver Extension, What Extension Service Solves Captcha Automatically?

Solve CAPTCHAs automatically with the CapSolver browser extension — the fastest, AI-powered CAPTCHA solver for Chrome

Extension
Logo of CapSolver

Sora Fujimoto

21-Oct-2025

Captcha Solver Extensions
Captcha Solver Extensions, How to Install Captcha Solver Extension

How to install and use the CapSolver browser extension — the best AI-powered CAPTCHA solver for Chrome and Firefox. Discover its benefits, automation integration, and easy setup guide for effortless CAPTCHA handling.

Extension
Logo of CapSolver

Lucas Mitchell

20-Oct-2025

reCAPTCHA-Auto-Solver
How to Solve reCAPTCHAs Automatically | the Best reCAPTCHA Auto Solver

Discover the ultimate reCAPTCHA Auto Solver. Learn how CapSolver's AI-powered Chrome Extension automates reCAPTCHA v2, v3 solving with high accuracy and efficiency. Boost your productivity today.

Extension
Logo of CapSolver

Ethan Collins

20-Oct-2025

Auto Captcha Solver Chrome
Auto Captcha Solver Chrome: CapSolver Auto Solver Extension Download

Looking for the best Chrome extension to automatically solve captchas? CapSolver Auto Solver Extension offers a fast, AI-powered way to bypass reCAPTCHA and other verification challenges.

Extension
Logo of CapSolver

Lucas Mitchell

18-Oct-2025

Auto CAPTCHA Solver
Auto CAPTCHA Solver, Best CAPTCHA Solver Extension

Learn how to install and use the CapSolver browser extension, the most efficient auto CAPTCHA solver for Chrome, Firefox, Puppeteer, and Selenium. Automate Captcha with AI-powered browser integration.

Extension
Logo of CapSolver

Sora Fujimoto

17-Oct-2025

Auto captcha solver on chrome: CapSolver
What is the Best Auto Captcha Solver on Chrome

CapSolver for Chrome automatically solves CAPTCHAs, saving time and providing a seamless browsing experience.

Extension
Logo of CapSolver

Lucas Mitchell

16-Oct-2025