Search code examples
pythonseleniumwebdrivercaptcha2captcha

Hcaptcha + 2captcha/anticaptcha in Python Selenium Chromedriver


I am trying to bypass hcaptcha on cloudflare anti-ddos loading page using webdriver in python selenium. Basically i have got to the point when the token is put in h-captcha-response and g-recaptcha-response fields and i can submit hcaptcha form. The problem is when i try to submit it, hcaptcha area looks like it reloads and after trying to submit it again it constantly happens. Is there a chance for some kind of ban on my user-agent? What's more i sometimes get 502 http error after submitting the form.

driver.execute_script(f"document.getElementsByName('h-captcha-response')[0].innerHTML = '{token}';")
time.sleep(1)
driver.execute_script(f"document.getElementsByName('g-recaptcha-response')[0].innerHTML = '{token}';")
time.sleep(1)
driver.execute_script("document.getElementById('challenge-form').submit();")

Solution

  • 10 months ago, you needed

    driver.execute_script(f"grecaptcha.getResponse = function(){return '{token}'}")
    

    Now you need inject js code before all scripts on a page with injecting hcaptcha object with special attribute render for intercept a callback function. https://alexandrsokolov-41020.medium.com/%D1%80%D0%B5%D1%88%D0%B0%D0%B5%D0%BC-hcaptcha-9eebf2ee3c5a