Skip to content

Instantly share code, notes, and snippets.

@ruvnet
Created November 16, 2024 14:32
Show Gist options
  • Save ruvnet/b169200e32ccec4a9116c5e4efbc6779 to your computer and use it in GitHub Desktop.
Save ruvnet/b169200e32ccec4a9116c5e4efbc6779 to your computer and use it in GitHub Desktop.
automate the process of solving CAPTCHAs using a desktop computer, you can combine several approaches involving automation tools

To automate the process of solving CAPTCHAs using a desktop computer, you can combine several approaches involving automation tools, CAPTCHA solving services, and scripting. Here’s a detailed guide on how to set this up:

Using Automation Tools

Power Automate Desktop

You can use Power Automate Desktop (formerly Microsoft Power Automate Desktop) to automate the interaction with the CAPTCHA. Here’s a general outline based on the videos and descriptions provided:

  1. Capture CAPTCHA Image:

    • Use Power Automate Desktop to capture a screenshot of the CAPTCHA challenge.
    • Extract the CAPTCHA image from the screenshot[1][4].
  2. Send Image for Human Verification:

    • If the CAPTCHA is too complex for automated solving, send the image to a user via email or another communication channel.
    • Use Adaptive Cards in Outlook to get the user's response. This allows the user to select the correct images or provide the solution manually[1][4].
  3. Automate User Actions:

    • Once the user responds, the bot can automate the actions to input the solution back into the CAPTCHA field.
    • Use Power Automate Desktop to simulate mouse clicks and keyboard inputs based on the user's response.

Integrating CAPTCHA Solving Services

Using CapSolver or 2Captcha

For a more automated approach, you can integrate CAPTCHA solving services like CapSolver or 2Captcha.

CapSolver

Here’s how you can use CapSolver:

  1. Sign Up and Get API Key:

    • Register for a CapSolver account and obtain your API key[3][5].
  2. Capture and Send CAPTCHA Image:

    • Use Power Automate Desktop or another automation tool to capture the CAPTCHA image.
    • Send the CAPTCHA image to CapSolver using their API.
  3. Receive and Input Solution:

    • Receive the solved CAPTCHA solution from CapSolver.
    • Use Power Automate Desktop to input the solution into the CAPTCHA field.
import capsolver

capsolver.api_key = "Your Capsolver API Key"

PAGE_URL = "PAGE_URL"
PAGE_KEY = "PAGE_SITE_KEY"

def solve_recaptcha_v2(url, key):
    solution = capsolver.solve({
        "type": "ReCaptchaV2TaskProxyless",
        "websiteURL": url,
        "websiteKey": key,
    })
    return solution

def main():
    print("Solving reCaptcha v2")
    solution = solve_recaptcha_v2(PAGE_URL, PAGE_KEY)
    print("Solution: ", solution)
    # Use Power Automate Desktop to input the solution

if __name__ == "__main__":
    main()

2Captcha

Similarly, you can use 2Captcha by integrating it into your automation workflow:

  1. Register and Get API Key:

    • Register for a 2Captcha account and obtain your API key[2].
  2. Capture and Send CAPTCHA Image:

    • Capture the CAPTCHA image using your automation tool.
    • Send the image to 2Captcha for solving.
  3. Receive and Input Solution:

    • Receive the solved CAPTCHA solution from 2Captcha.
    • Use your automation tool to input the solution into the CAPTCHA field.

Example Workflow

Here is a more detailed example of how you might set this up using Power Automate Desktop and CapSolver:

Step-by-Step Process

  1. Initialize Power Automate Desktop:

    • Start Power Automate Desktop and create a new flow.
    • Use the "Take a screenshot" action to capture the CAPTCHA image.
  2. Send Image to CapSolver:

    • Use the "HTTP Request" action to send the CAPTCHA image to CapSolver.
    • Pass the necessary parameters such as the website URL and site key.
  3. Receive Solution:

    • Receive the response from CapSolver containing the solved CAPTCHA solution.
    • Parse the response to extract the solution.
  4. Input Solution:

    • Use the "Mouse" and "Keyboard" actions in Power Automate Desktop to input the solution into the CAPTCHA field.
  5. Handle Complex CAPTCHAs:

    • If the CAPTCHA is too complex, send it to a user for manual verification using Adaptive Cards in Outlook.
    • Once the user responds, use the response to input the solution.

Here is a simplified example script to illustrate the integration with CapSolver:

import capsolver
import pyautogui

# Set up CapSolver API key
capsolver.api_key = "Your Capsolver API Key"

# Capture CAPTCHA image using Power Automate Desktop or pyautogui
captcha_image = pyautogui.screenshot(region=(100, 100, 300, 100))  # Adjust the region as needed

# Save the image to a file
captcha_image.save('captcha.png')

# Send the image to CapSolver
solution = capsolver.solve({
    "type": "ReCaptchaV2TaskProxyless",
    "websiteURL": "PAGE_URL",
    "websiteKey": "PAGE_SITE_KEY",
    "image": 'captcha.png',
})

# Input the solution using pyautogui
pyautogui.typewrite(solution['gRecaptchaResponse'])

This approach combines the automation capabilities of Power Automate Desktop with the CAPTCHA solving services of CapSolver or 2Captcha, providing a robust solution for automating CAPTCHA challenges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment