Created
July 27, 2023 11:17
-
-
Save alperensert/9ccc39c4d85ed4d385bd825690b5cfda to your computer and use it in GitHub Desktop.
Bypass HCaptcha with Selenium & CapSolver Extesion [PYTHON]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from time import sleep | |
from selenium import webdriver | |
from selenium.webdriver.chrome.service import Service | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
from selenium.webdriver.common.by import By | |
def main(): | |
current_working_directory = os.getcwd() | |
chrome_driver_path = current_working_directory + "/chromedriver" | |
capsolver_extension_path = current_working_directory + "/capsolver_extension" # get it from capsolver.com | |
chrome_service = Service(executable_path=chrome_driver_path) | |
chrome_options = webdriver.ChromeOptions() | |
chrome_options.add_argument( | |
"--load-extension={0}".format(capsolver_extension_path)) | |
driver = webdriver.Chrome(service=chrome_service, options=chrome_options) | |
driver.get("https://accounts.hcaptcha.com/demo") | |
wait = WebDriverWait(driver, timeout=100) | |
frame_selector = "#hcaptcha-demo > iframe" | |
frame_attribute = "data-hcaptcha-response" | |
wait.until(EC.element_attribute_to_include( | |
(By.CSS_SELECTOR, frame_selector), frame_attribute)) | |
while True: | |
frame = driver.find_element(By.CSS_SELECTOR, frame_selector) | |
response = frame.get_attribute(frame_attribute) | |
if len(response) > 100: | |
break | |
sleep(1) | |
print("Waiting for captcha solution..") | |
form = driver.find_element(By.CSS_SELECTOR, "#hcaptcha-demo-form") | |
form.submit() | |
print("It's good to solve captchas like that!") | |
sleep(20) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment