In this article, we've developed a detailed guide on how to bypass reCAPTCHA using the Selenium and fully auto fill method.
Learn how to automatically solve Google captcha reCAPTCHA using Selenium and the auto filler in this step-by-step guide.
reCAPTCHA Auto Bypass Using Selenium and Auto Filler
This article explain how to automate image-based reCAPTCHA bypass challenges (3x3 or 4x4 grids) using the reCAPTCHA solver and Selenium lib and the 2Captcha (captcha solver).
The programmatic script for reCAPTCHA bypass can be described as follows:
- The script detects the presence of a reCAPTCHA challenge on the web page.
- It captures the reCAPTCHA
- The challenge is sent to the captcha solver API, which uses a distributed solver system to provide the correct solution
- Once the solution is returned, the script simulates human-like interactions by clicking or submitting the provided solution, mimicking human behavior to avoid detection.
This method automates the entire process, allowing for seamless CAPTCHA bypassing in web automation tasks.
Installation and Usage
To use this script, clone the repository, install the necessary dependencies, and run the provided example.
This will set up the environment and demonstrate how to bypass reCAPTCHA automatically with the script in action. Here's how:
# Clone the repositorygit clone git@github.com/2captcha/selenium-recaptcha-solver-using-grid.gitcd selenium-recaptcha-solver-using-grid# Install dependenciespip install -r requirements.txt# Run the scriptpython main.py`
Configuration
To use the script, you'll need to configure your 2Captcha API key. Set the APIKEY
environment variable as follows:
export APIKEY=your_api_key
How It Works
This script uses the grid-based method to solve reCAPTCHA challenges. Here's a step-by-step breakdown of how it works:
- Extracting the CAPTCHA: The reCAPTCHA challenge image and necessary parameters are extracted programmatically.
- Sending Data: The image data is sent to the captcha solver API, where it’s solved using the grid method (e.g., identifying which cells contain the correct objects).
- Clicking: After receiving the solution, which includes the grid cell numbers to click, Selenium simulates user interaction by clicking the specified cells within the reCAPTCHA widget. Finally, the script clicks the
Verify
button to complete the challenge.
Example of a successful response from the extraction script might look like this:
{ rows: 3, columns: 3, type: 'GridTask', comment: 'Select all images with crosswalks Click verify once there are none left', body: 'XXXXXXXX'}
Example of a response after solving the reCAPTCHA:
{ status: 1, data: 'click:3/6/8', id: 'XXXXXXXX' }
In the response click:3/6/8
, the numbers represent the grid cells that need to be clicked. The response click:3/6/8
means you should click on the CAPTCHA squares numbered 3, 6, and 8. The cells are numbered starting from the top-left corner, moving left to right, row by row. In the screenshot below, you can visually identify which squares correspond to the response click:3/6/8
.
For the response click:3/6/8
, you would click the squares in the third, sixth, and eighth positions.
Typically, to fully solve a CAPTCHA, you need to pass around 1-5 challenges. However, in more complex cases, there might be additional tasks to complete.
Features
- Selenium WebDriver: Interacts with the browser and manipulates reCAPTCHA elements on the page.
- 2Captcha API: Solves image-based captchas using artificial intelligence that provides high-speed solutions.
- Handles both 3x3 and 4x4 captchas with custom logic for each.
- Modular design with separated logic into helper classes for easy code maintenance and future expansion.
- Tracks image updates and handles captcha error messages efficiently using custom error handling.
Pros
- Token-Free Verification: This approach eliminates the need to manage or manually inject reCAPTCHA tokens. It mimics human behavior by accurately clicking the appropriate regions in the CAPTCHA challenge.
- Streamlined Logic: By leveraging reCAPTCHA’s built-in validation mechanism, this method bypasses the complexities of token management, simplifying the process.
The primary advantage of this method is that it avoids direct token handling, which reduces complexity. It focuses on interacting with the visual elements of the CAPTCHA, clicking the correct regions, and pressing the Verify
button, leaving the validation up to reCAPTCHA’s internal logic.
In cases where additional security layers such as tracking or complex token mechanisms are implemented, token-based solutions become more difficult. This click-based method is especially useful when token-based bypassing is too intricate.
Cons
- Higher Complexity: This method introduces additional coding requirements and demands more time to properly handle user interactions.
- Variable Costs and Performance: The cost and time required to solve CAPTCHA challenges may fluctuate based on the difficulty of the image challenge.
- Reliance on Browser Automation: This solution depends on browser automation tool Selenium to execute the reCAPTCHA bypass successfully. Browser automation ensures proper interaction with reCAPTCHA and that the captcha is solved and submitted correctly.
Error Handling
ERROR_CAPTCHA_UNSOLVABLE
: CAPTCHA may be too complex for the 2Captcha service to solve, resulting in this error. You should build retry logic or an escalation mechanism when encountering this issue.Blocking by reCAPTCHA
: Too many failed attempts from the same IP can result in temporary blocking by reCAPTCHA. To avoid this, you can either change your IP address or wait before retrying. If blocked, the following message may appear:Try again later. Your computer or network may be sending automated queries. To protect our users, we can't process your request.
References
If you're working with JavaScript, we also have a similar example that uses JavaScript captcha solver along with Puppeteer. You can find the example in the repository - reCAPTCHA Solver Using 2Captcha and Puppeteer.