Search code examples
pythonapiseleniumrecaptcha2captcha

How to integrate captcha bypass using 2captcha api in Python Selenium


I'm making a reddit account auto-generator. I want to ask how can I use 2captcha's api to bypass recaptcha. Because after entering the username and password, the new captcha box appears, I have researched on the 2captcha page, the video tutorials on youtube but still have not found a way. Thanks everyone and have a nice day!

import pandas as pd
from selenium import webdriver
from selenium.webdriver.common.proxy import *
from selenium.webdriver.common.by import By
from time import sleep
import time
import openpyxl
import requests
import pandas as pd
from twocaptcha import TwoCaptcha

solver = TwoCaptcha('YOUR_API_KEY')

# Load the Excel file
...
# Loop through the rows of the DataFrame
...
   # Get the latest IP address from the proxy service
   ...
   # Update the capabilities object to use the new proxy
   ...
   # Create a new instance of the webdriver with the updated capabilities
   # Use selenium to signup with the username and password
   
   result = solver.recaptcha(sitekey='6LeTnxkTAAAAAN9QEuDZRpn90WwKk_R1TRW_g-JC',
   url='https://www.reddit.com/account/register/')

Solution

  • Look at the TwoCaptcha documentation!

    # Import the required libraries
    from twocaptcha import TwoCaptcha
    
    # Create a new TwoCaptcha solver object
    solver = TwoCaptcha('YOUR_API_KEY')
    
    # Solve the reCAPTCHA on the Reddit signup page
    result = solver.recaptcha(sitekey='6LeTnxkTAAAAAN9QEuDZRpn90WwKk_R1TRW_g-JC',
                             url='https://www.reddit.com/account/register/')
    
    # Check the result to see if the reCAPTCHA was successfully solved
    if result['status'] == 0:
        # Success
    else:
        # Error