Skip to main content

nonoCAPTCHA Examples

nonoCAPTCHA Examples.

Here is a detailed step-by-step tutorial on how to use the nonoCAPTCHA library with Python. This library provides a simple way to bypass Google reCAPTCHA using the selenium package.

Prerequisites

Before getting started, make sure you have the following prerequisites installed on your system:

  • Python (version 3.6 or higher)
  • selenium package (pip install selenium)
  • Google Chrome web browser
  • Chrome WebDriver executable

You can download the Chrome WebDriver from the following link: Chrome WebDriver

Once you have everything set up, you're ready to start using the nonoCAPTCHA library.

Step 1: Import the necessary modules

Start by importing the required modules: selenium, nonocaptcha, and webdriver_manager.

from selenium import webdriver
from nonocaptcha import Solver
from webdriver_manager.chrome import ChromeDriverManager

Step 2: Create a WebDriver instance

Next, create an instance of the Chrome WebDriver using the webdriver.Chrome() function. Make sure to provide the path to the Chrome WebDriver executable.

driver = webdriver.Chrome(ChromeDriverManager().install())

Step 3: Initialize the Solver

Now, initialize the Solver object by passing the WebDriver instance to it.

solver = Solver(driver)

Example 1: Solving reCAPTCHA on a webpage

Let's start with a simple example of solving a reCAPTCHA on a webpage. We'll use the solve() method of the Solver object to automatically solve the reCAPTCHA.

solver.solve(url='https://example.com')

Expected Output:

  • The Solver will open the specified URL in the Chrome browser.
  • It will automatically solve the reCAPTCHA and proceed with the rest of the code.

Example 2: Solving reCAPTCHA with custom options

You can also provide custom options to the solve() method. For example, you can specify the maximum number of attempts to solve the reCAPTCHA.

solver.solve(url='https://example.com', max_attempts=3)

Expected Output:

  • The Solver will make a maximum of 3 attempts to solve the reCAPTCHA on the specified URL.
  • If it fails to solve the reCAPTCHA within the given attempts, it will raise a CaptchaError.

Example 3: Getting the response token

If you want to retrieve the response token after solving the reCAPTCHA, you can use the get_response_token() method of the Solver object.

response_token = solver.get_response_token()

Expected Output:

  • The Solver will return the response token value as a string.

Example 4: Checking if a page contains a reCAPTCHA

You can check if a webpage contains a reCAPTCHA by using the has_recaptcha() method of the Solver object.

has_recaptcha = solver.has_recaptcha(url='https://example.com')

Expected Output:

  • The Solver will open the specified URL in the Chrome browser.
  • It will check if the page contains a reCAPTCHA and return a boolean value indicating the result.

Example 5: Capturing a screenshot of the page

You can capture a screenshot of the web page after the reCAPTCHA is solved using the capture_screenshot() method of the Solver object.

solver.solve(url='https://example.com')
solver.capture_screenshot('screenshot.png')

Expected Output:

  • The Solver will open the specified URL in the Chrome browser.
  • It will solve the reCAPTCHA and then capture a screenshot of the page, saving it as 'screenshot.png'.

Example 6: Retrieving the page source

You can retrieve the HTML source code of the page after the reCAPTCHA is solved using the get_page_source() method of the Solver object.

solver.solve(url='https://example.com')
page_source = solver.get_page_source()

Expected Output:

  • The Solver will open the specified URL in the Chrome browser.
  • It will solve the reCAPTCHA and then return the page source code as a string.

Example 7: Controlling the Chrome browser

You can also control the Chrome browser directly using the WebDriver instance. For example, you can navigate to a different page after solving the reCAPTCHA.

solver.solve(url='https://example.com')
driver.get('https://example.com/other-page')

Expected Output:

  • The Solver will open the specified URL in the Chrome browser.
  • It will solve the reCAPTCHA and then navigate to the 'other-page' URL.

Example 8: Handling reCAPTCHA v3

The nonoCAPTCHA library also supports solving reCAPTCHA v3 challenges. You can specify the action and minimum score required to solve the reCAPTCHA.

solver.solve(url='https://example.com', action='login', min_score=0.5)

Expected Output:

  • The Solver will open the specified URL in the Chrome browser.
  • It will solve the reCAPTCHA v3 challenge with the specified action and minimum score.

Example 9: Solving multiple reCAPTCHAs on a page

If a page contains multiple reCAPTCHA challenges, you can solve them one by one using the solve_all() method of the Solver object.

solver.solve_all(url='https://example.com')

Expected Output:

  • The Solver will open the specified URL in the Chrome browser.
  • It will solve all the reCAPTCHA challenges on the page, one by one.

Example 10: Handling custom delays

You can add custom delays between solving reCAPTCHA challenges using the delay parameter of the Solver object.

solver = Solver(driver, delay=1)
solver.solve_all(url='https://example.com')

Expected Output:

  • The Solver will open the specified URL in the Chrome browser.
  • It will solve all the reCAPTCHA challenges on the page with a delay of 1 second between each challenge.

That's it! You now have a detailed understanding of how to use the nonoCAPTCHA library in Python to bypass Google reCAPTCHA. Feel free to explore more features and options provided by the library to suit your specific needs.