hCaptcha solver and bypasser for Python Selenium. Simple website to try to solve hCaptcha.

Overview

hCaptcha solver for Python Selenium.

Many thanks to engageub for his hCaptcha solver userscript.
This script is solely intended for the use of educational purposes only and not to abuse any website.
The solving speed depends on your PC's compute power and Internet connection.

Table of contents:

Instructions:

  • Download this repository or clone it:
git clone https://github.com/maximedrn/hcaptcha-solver-python-selenium.git
  • It requires Python 3.7 or a newest version.
  • Install pip to be able to have needed Python modules.
  • Download and install Google Chrome.
  • Download the ChromeDriver executable that is compatible with the actual version of your Google Chrome browser and your OS (Operating System). Refer to: What version of Google Chrome do I have?
  • Extract the executable from the ZIP file and copy/paste it in the assets/ folder of the repository.
  • Open a command prompt in repository folder and type:
pip install -r requirements.txt
  • Then type to see a demonstration:
python main.py

This code can be implemented in any project. You just have to had the hCaptcha class without the demonstration() method in your Python project repository. Then init the class in your Python code. You should have something like this:

hcaptcha-solver.py

"""
@author: Maxime.

Github: https://github.com/maximedrn
Demonstration website: https://maximedrn.github.io/hcaptcha-test/
Version: 1.0
"""

# Colorama module: pip install colorama
from colorama import init, Fore, Style

# Selenium module imports: pip install selenium
from selenium import webdriver
from selenium.common.exceptions import TimeoutException as TE
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait as WDW
from selenium.webdriver.common.by import By

# Python default import.
import sys
import os


"""Colorama module constants."""
init(convert=True)  # Init colorama module.
red = Fore.RED  # Red color.
green = Fore.GREEN  # Green color.
yellow = Fore.YELLOW  # Yellow color.
reset = Style.RESET_ALL  # Reset color attribute.


class hCaptcha:
    """Main class of the hCaptcha solver."""

    def __init__(self) -> None:
        """Set path of used file and start webdriver."""
        self.webdriver_path = 'assets/chromedriver.exe'
        self.extension_path = 'assets/Tampermonkey.crx'
        self.driver = self.webdriver()  # Start new webdriver.

    def webdriver(self):
        """Start webdriver and return state of it."""
        options = webdriver.ChromeOptions()  # Configure options for Chrome.
        options.add_extension(self.extension_path)  # Add extension.
        options.add_argument('--lang=en')  # Set webdriver language to English.
        # options.add_argument("headless")  # Headless ChromeDriver.
        options.add_argument('log-level=3')  # No logs is printed.
        options.add_argument('--mute-audio')  # Audio is muted.
        options.add_argument("--enable-webgl-draft-extensions")
        options.add_argument("--ignore-gpu-blocklist")
        driver = webdriver.Chrome(self.webdriver_path, options=options)
        driver.maximize_window()  # Maximize window to reach all elements.
        return driver

    def element_clickable(self, element: str) -> None:
        """Click on element if it's clickable using Selenium."""
        WDW(self.driver, 5).until(EC.element_to_be_clickable(
            (By.XPATH, element))).click()

    def element_visible(self, element: str):
        """Check if element is visible using Selenium."""
        return WDW(self.driver, 20).until(EC.visibility_of_element_located(
            (By.XPATH, element)))

    def window_handles(self, window_number: int) -> None:
        """Check for window handles and wait until a specific tab is opened."""
        WDW(self.driver, 30).until(lambda _: len(
            self.driver.window_handles) == window_number + 1)
        # Switch to asked tab.
        self.driver.switch_to.window(self.driver.window_handles[window_number])

    def download_userscript(self) -> None:
        """Download the hCaptcha solver userscript."""
        try:
            print('Installing the hCaptcha solver userscript.', end=' ')
            self.window_handles(1)  # Wait that Tampermonkey tab loads.
            self.driver.get('https://greasyfork.org/en/scripts/425854-hcaptcha'
                            '-solver-automatically-solves-hcaptcha-in-browser')
            # Click on "Install" Greasy Fork button.
            self.element_clickable('//*[@id="install-area"]/a[1]')
            # Click on "Install" Tampermonkey button.
            self.window_handles(2)  # Switch on Tampermonkey install tab.
            self.element_clickable('//*[@value="Install"]')
            self.window_handles(1)  # Switch to Greasy Fork tab.
            self.driver.close()  # Close this tab.
            self.window_handles(0)  # Switch to main tab.
            print(f'{green}Installed.{reset}')
        except TE:
            sys.exit(f'{red}Failed.{reset}')

def cls() -> None:
    """Clear console function."""
    # Clear console for Windows using 'cls' and Linux & Mac using 'clear'.
    os.system('cls' if os.name == 'nt' else 'clear')
    
if __name__ == '__main__':

    cls()  # Clear console.

    print('hCaptcha Solver'
          f'\n{green}Made by Maxime.'
          f'\n@Github: https://github.com/maximedrn{reset}')

your-script.py

from hcaptcha-solver import hCaptcha

# Your code.
# ...

if __name__ == '__main__':
    hcaptcha = hCaptcha()  # Init hCaptcha class.
    hcaptcha.download_userscript()  # Download the hCaptcha solver userscript.

Demonstration:

Demonstration GIF.

Simple website to try to solve hCaptcha.

  • Open a new tab and go to the website hCaptcha test.
  • Website preview:

Website preview

Comments
  • FireFox

    FireFox

    each time i do it with firefox:

    # Colorama module: pip install colorama
    from colorama import init, Fore, Style
    
    # Selenium module imports: pip install selenium
    from selenium import webdriver
    from selenium.common.exceptions import TimeoutException as TE
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.support.ui import WebDriverWait as WDW
    from selenium.webdriver.common.by import By
    
    # Python default import.
    import sys
    import os
    
    
    """Colorama module constants."""
    init(convert=True)  # Init colorama module.
    red = Fore.RED  # Red color.
    green = Fore.GREEN  # Green color.
    yellow = Fore.YELLOW  # Yellow color.
    reset = Style.RESET_ALL  # Reset color attribute.
    
    
    class hCaptcha:
        """Main class of the hCaptcha solver."""
    
        def __init__(self) -> None:
            """Set path of used file and start webdriver."""
            self.webdriver_path = 'geckodriver.exe'
            self.extension_path = 'cap.xpi'
            self.driver = self.webdriver()  # Start new webdriver.
    
        def webdriver(self):
            """Start webdriver and return state of it."""
            options = webdriver.ChromeOptions()  # Configure options for Chrome.
            options.add_extension(self.extension_path)  # Add extension.
            options.add_argument('--lang=en')  # Set webdriver language to English.
            # options.add_argument("headless")  # Headless ChromeDriver.
            options.add_argument('log-level=3')  # No logs is printed.
            options.add_argument('--mute-audio')  # Audio is muted.
            options.add_argument("--enable-webgl-draft-extensions")
            options.add_argument("--ignore-gpu-blocklist")
            driver = webdriver.Chrome(self.webdriver_path, options=options)
            driver.maximize_window()  # Maximize window to reach all elements.
            return driver
    
        def element_clickable(self, element: str) -> None:
            """Click on element if it's clickable using Selenium."""
            WDW(self.driver, 5).until(EC.element_to_be_clickable(
                (By.XPATH, element))).click()
    
        def element_visible(self, element: str):
            """Check if element is visible using Selenium."""
            return WDW(self.driver, 20).until(EC.visibility_of_element_located(
                (By.XPATH, element)))
    
        def window_handles(self, window_number: int) -> None:
            """Check for window handles and wait until a specific tab is opened."""
            WDW(self.driver, 30).until(lambda _: len(
                self.driver.window_handles) == window_number + 1)
            # Switch to asked tab.
            self.driver.switch_to.window(self.driver.window_handles[window_number])
    
        def download_userscript(self) -> None:
            """Download the hCaptcha solver userscript."""
            try:
                print('Installing the hCaptcha solver userscript.', end=' ')
                self.window_handles(1)  # Wait that Tampermonkey tab loads.
                self.driver.get('https://greasyfork.org/en/scripts/425854-hcaptcha'
                                '-solver-automatically-solves-hcaptcha-in-browser')
                # Click on "Install" Greasy Fork button.
                self.element_clickable('//*[@id="install-area"]/a[1]')
                # Click on "Install" Tampermonkey button.
                self.window_handles(2)  # Switch on Tampermonkey install tab.
                self.element_clickable('//*[@value="Install"]')
                self.window_handles(1)  # Switch to Greasy Fork tab.
                self.driver.close()  # Close this tab.
                self.window_handles(0)  # Switch to main tab.
                print(f'{green}Installed.{reset}')
            except TE:
                sys.exit(f'{red}Failed.{reset}')
    
    def cls() -> None:
        """Clear console function."""
        # Clear console for Windows using 'cls' and Linux & Mac using 'clear'.
        os.system('cls' if os.name == 'nt' else 'clear')
        
    if __name__ == '__main__':
    
        cls()  # Clear console.
    
        print('hCaptcha Solver'
              f'\n{green}Made by Maxime.'
              f'\n@Github: https://github.com/maximedrn{reset}')
    
    import selenium
    from selenium import *
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    import random
    import sys
    from time import sleep
    import os
    from selenium.webdriver.common.keys import Keys
    import getpass
    from selenium.webdriver.common.action_chains import ActionChains
    from hcaptcha import hCaptcha
    from selenium.webdriver.firefox.options import Options
    
    os.system('title Kolhax TT acc generator PRO')
    
    class bcolors:
        HEADER = '\033[95m'
        OKBLUE = '\033[94m'
        OKCYAN = '\033[96m'
        OKGREEN = '\033[92m'
        WARNING = '\033[93m'
        FAIL = '\033[91m'
        ENDC = '\033[0m'
        BOLD = '\033[1m'
        UNDERLINE = '\033[4m'
    
    def clear():
        os.system('cls')
    
    clear()
    
    print('''
    Hi, beafore starting...
    you would need to have Firefox installed,
    
    ** This service need to manually phone 
    ** verify the generate accounts
    
    ''')
    os.system('pause')
    clear()
    
    options = Options()
    profile = webdriver.FirefoxProfile()
    profile.set_preference('intl.accept_languages', 'en-GB')
    driver = webdriver.Firefox(options=options,firefox_profile=profile)
    clear()
    
    path = os.getcwd()
    extension_path = path + "\\cap.xpi"
    driver.install_addon(extension_path)
    driver.get("about:support")
    sleep(5)
    driver.close()
    sleep(2)
    if __name__ == '__main__':
        hcaptcha = hCaptcha()  # Init hCaptcha class.
        hcaptcha.download_userscript()  # Download the hCaptcha solver userscript.
    clear()
    print(f'{bcolors.WARNING}[{bcolors.ENDC}+{bcolors.WARNING}]{bcolors.ENDC} Hcaptcha Accessibility Gained!')
    sleep(3)
    clear()
    
    enhancement 
    opened by KeparYTbcc 20
  • Script is deleted

    Script is deleted

    when i opened link for the script it says the script has been disabled idk if its error popping up for me only but yesterday i have opened same script and it was working

    bug enhancement 
    opened by DRehman-Bilal 8
  • __init__() got an unexpected keyword argument 'log_level'

    __init__() got an unexpected keyword argument 'log_level'

    Hello there, I just tried to use this, but got the following error messages:

    Traceback (most recent call last):
    
    File "D:/PycharmProjects/pythonProject/hcaptcha-solver/main.py", line 43, in <module>
      browser=1, headless=False, comments=True, download=False)
    File "D:\PycharmProjects\pythonProject\hcaptcha-solver\app\hcaptcha.py", line 59, in __init__
      self.driver = self.geckodriver()
    File "D:\PycharmProjects\pythonProject\hcaptcha-solver\app\hcaptcha.py", line 97, in geckodriver
      log_level=0).install()), options=options)
    
    TypeError: __init__() got an unexpected keyword argument 'log_level'`
    
    documentation no-issue-activity 
    opened by nileszzy 2
  • [Question] Support captcha_rqdata param?

    [Question] Support captcha_rqdata param?

    Hey that AI solver support rqdata (hcaptcha enterprise) param? For example Discord giving it in that form:

    {
       "captcha_key":[
          "You need to update your app to join this server."
       ],
       "captcha_sitekey":"a9b5fb07-92ff-493f-86fe-352a2803b3df",
       "captcha_service":"hcaptcha",
       "captcha_rqdata":"0Ji4wdKunnOywUKq5nv3KMJ6tqGH9wcWBl0Q0VM8VuvRIqcKk+SwA9vHPPUCePb/PUWD2YIDU/uucUImTNwL48p1YTzzdwTQXN9jg4pJ0e43EqFGSPC1KTdXS3oIu0sY6OBcxZft05er3eqeSSfUNfMZYeo8KIcOUcM7HX6r",
       "captcha_rqtoken":"IlpxMis0ZlNHdEJ3ZEZ4bUU4dFo4L3UwUFBQc1JhM1hoTUlDTTcxcGtaZkUxUU5XRzNEblZuL2ZwQ01mNjVRSExORVZxRVE9PXozeW1XYzhaQVBQV3g4dkci.Yk3_qw.t18rr3DCRCYfvQKxRlu73vrTQM8"
    }
    

    Best Regards

    opened by ChronoBrake 1
  • Could I use the hcaptcha test site you built?

    Could I use the hcaptcha test site you built?

    Hi, I used the hcaptcha test site you built in the hcaptcha-challenger project I created recently.

    In addition, I noticed that the performance issues were mentioned in the previous discussion of this extension.

    • https://github.com/maximedrn/hcaptcha-solver-python-selenium/issues/1
    • https://github.com/maximedrn/hcaptcha-solver-python-selenium/issues/3

    Coincidentally, all these problems are solved in hcaptcha-challenger.🤷‍♀️

    • The recognition task is done independently and not with the help of extensions, so the browser can be started headless.
    • The recognition module uses a self-trained yolov5n6(onnx) to perform two challenging rounds of the recognition task in one second in extreme cases.This model has excellent penetration of the hcaptcha challenge, is less than 15MB in size, and can run on almost any embedded device.

    In the following demo, I am using yolov5s6(onnx) with a larger parameter size to start the solution. if you specify yolov5n6(onnx) to start, the detection speed can be twice as fast...🤦‍♂️ hcaptcha-challenger-demo

    opened by QIN2DIM 1
  • Update main.py

    Update main.py

    in line 45 this command line is not working correctly replace with:_options.add_experimental_option('prefs', {'intl.accept_languages': 'en,en_US'})

    see in this post at stackoverflow for more information: https://stackoverflow.com/questions/55150118/trouble-modifying-the-language-option-in-selenium-python-bindings

    opened by lobatim 1
  • Headless Ubuntu Server support

    Headless Ubuntu Server support

    Hello, Is there a way to get this working on headless Ubuntu Server? I installed google chrome, downloaded corresponding chromedriver and changed the path in main.py. If I leave the line # options.add_argument("headless") # Headless ChromeDriver commented out then it says that Chrome has crashed, and if I remove the # then it says selenium.common.exceptions.WebDriverException: Message: unknown error: failed to wait for extension background page to load: chrome-extension://dhdgffkkebhmkfjojejmpbldmpobfkfo/background.html from unknown error: page could not be found: chrome-extension://dhdgffkkebhmkfjojejmpbldmpobfkfo/background.html

    opened by darvd29 1
  • To slow have to evolve to be useful 😅

    To slow have to evolve to be useful 😅

    So the Script is really cool but the detection is to slow and makes to many flaws but still an awesome but not good enough to use it for account creation stuff

    opened by JokersCat 1
  • Update

    Update

    Hi,

    First of all i would like to thank you for your work !

    Now, i was wondering if there is any chance of adding new animals ? There is a lot of new animals like lion, giraffe or parrot. Even your example is not working anymore :(

    Thanks

    opened by Skiizoo 0
  • Added webdriver_manager and option to use as context manager

    Added webdriver_manager and option to use as context manager

    • Added the webdriver-manager library to automatically manage drivers for chrome driver
    • Added the __enter__ and __exit__ methods so that the hCaptcha class could be used as a context manager
    • Organized the imports and requirements.txt using the isort library
    opened by dobizz 0
  • hCaptcha asks for second click/maximum requests exceeded

    hCaptcha asks for second click/maximum requests exceeded

    WDW(hcaptcha.driver, 600).until(lambda _: len(hcaptcha.element_visible('//div[@class="h-captcha"]/iframe').get_attribute( 'data-hcaptcha-response')) > 0)

    suggest adding >X, instead of >0, since there could be string with "Maximum requests exceeded." and "Object Object" above 40 works fine

    wontfix 
    opened by saitishmukhametov 0
Owner
Maxime Dréan
French student and beginner developer. Learning code. Python, Java, JavaScript, React, HTML & CSS.
Maxime Dréan
A python bot using the Selenium library to auto-buy specified sneakers on the nike.com website.

Sneaker-Bot-UK A python bot using the Selenium library to auto-buy specified sneakers on the nike.com website. This bot is still in development and is

Daniel Hinds 4 Dec 14, 2022
This project demonstrates selenium's ability to extract files from a website.

This project demonstrates selenium's ability to extract files from a website. I've added the challenge of connecting over TOR. This package also includes a personal archive site built in NodeJS and Angular that allows users to filter and view downloaded files.

null 2 Jan 16, 2022
A simple python script that uses selenium(chrome web driver),pyautogui,time and schedule modules to enter google meets automatically

A simple python script that uses selenium(chrome web driver),pyautogui,time and schedule modules to enter google meets automatically

null 3 Feb 7, 2022
A simple script to login into twitter using Selenium in python.

Quick Talk A simple script to login into twitter using Selenium in python. I was looking for a way to login into twitter using Selenium in python. Sin

Lzy-slh 4 Nov 20, 2022
Multi-asset backtesting framework. An intuitive API lets analysts try out their strategies right away

Multi-asset backtesting framework. An intuitive API lets analysts try out their strategies right away. Fast execution of profit-take/loss-cut orders is built-in. Seamless with Pandas.

Epymetheus 39 Jan 6, 2023
Selenium-python but lighter: Helium is the best Python library for web automation.

Selenium-python but lighter: Helium Selenium-python is great for web automation. Helium makes it easier to use. For example: Under the hood, Helium fo

Michael Herrmann 3.2k Dec 31, 2022
Python package to easily work with selenium and manage tabs effectively.

Simple Selenium The aim of this package is to quickly get started with working with selenium for simple browser automation tasks. Installation Install

Vishal Kumar Mishra 1 Oct 27, 2021
Fully functioning price detector built with selenium and python

Fully functioning price detector built with selenium and python

mark sikaundi 4 Mar 30, 2022
This is a Python script for Github Bot which uses Selenium to Automate things.

github-follow-unfollow-bot This is a Python script for Github Bot which uses Selenium to Automate things. Pre-requisites :- Python A Github Account Re

Chaudhary Hamdan 10 Jul 1, 2022
This project is used to send a screenshot by email of your MyUMons schedule using Selenium python lib (headless mode)

MyUMonsSchedule Use MyUMonsSchedule python script to send a screenshot by email (Gmail) of your MyUMons schedule. If you use it on Windows, take care

Pierre-Louis D'Agostino 6 May 12, 2022
Akulaku Create NewProduct Automation using Selenium Python

Akulaku-Create-NewProduct-Automation Akulaku Create NewProduct Automation using Selenium Python Usage: 1. Install Python 3.9 2. Open CMD on Bot Folde

Rahul Joshua Damanik 1 Nov 22, 2021
Youtube Tool using selenium Python

YT-AutoLikeComment-AutoReportComment-AutoComment Youtube Tool using selenium Python Auto Comment Auto Like Comment Auto Report Comment Usage: 1. Insta

Rahul Joshua Damanik 1 Dec 13, 2021
Selenium Page Object Model with Python

Page-object-model (POM) is a pattern that you can apply it to develop efficient automation framework.

Mohammad Ifran Uddin 1 Nov 29, 2021
Aplikasi otomasi klik di situs popcat.click menggunakan Python dan Selenium

popthe-popcat Aplikasi Otomasi Klik di situs popcat.click. aplikasi ini akan secara otomatis melakukan click pada kucing viral itu, sehingga anda tida

cndrw_ 2 Oct 7, 2022
Python Webscraping using Selenium

Web Scraping with Python and Selenium The code shows how to do web scraping using Python and Selenium. We use as data the https://sbot.org.br/localize

Luís Miguel Massih Pereira 1 Dec 1, 2021
This file will contain a series of Python functions that use the Selenium library to search for elements in a web page while logging everything into a file

element_search with Selenium (Now With docstrings ?? ) Just to mention, I'm a beginner to all this, so it it's very possible to make some mistakes The

null 2 Aug 12, 2021
Compiles python selenium script to be a Window's executable

Problem Statement Setting up a Python project can be frustrating for non-developers. From downloading the right version of python, setting up virtual

Jerry Ng 8 Jan 9, 2023
Automated tests for OKAY websites in Python (Selenium) - user friendly version

Okay Selenium Testy Aplikace určená k testování produkčních webů společnosti OKAY s.r.o. Závislosti K běhu aplikace je potřeba mít v počítači nainstal

Viktor Bem 0 Oct 1, 2022
Whatsapp messages bulk sender using Python Selenium.

Whatsapp Sender Whatsapp Sender automates sending of messages via Whatsapp Web. The tool allows you to send whatsapp messages in bulk. This program re

Yap Yee Qiang 3 Jan 23, 2022