Solve Captcha with Python
I suppose you're using webdriving with Python (Selenium or similar).You should get the ANTICAPTCHA_KEY from your Anti-Captcha account. It gives acces to API to your Anti-Captcha credit.
I recommend you adding your ANTICAPTCHA_KEY to your environ. Execute the following command in shell or add the line to your bash file (.bashrc or similar)
export ANTICAPTCHA_KEY="your_key"
Your code could be like this:
import os from python3_anticaptcha import NoCaptchaTaskProxylessfrom selenium import webdriverANTICAPTCHA_KEY = os.environ["ANTICAPTCHA_KEY"]def solveCaptcha(): result = NoCaptchaTaskProxyless.NoCaptchaTaskProxyless( anticaptcha_key=ANTICAPTCHA_KEY ).captcha_handler( websiteURL="https://www.google.com/recaptcha/api2/demo", websiteKey="6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-", ) return result.get("solution").get("gRecaptchaResponse")
First, set webdriver, get the page and execute the function to assign the response to a variable.
driver = webdriver.Firefox()driver.get("https://www.google.com/recaptcha/api2/demo")captcha_response = solveCaptcha()
You can use the following script to make the grecaptcha response box visible, so you can see if it's working.
driver.execute_script( "arguments[0].style.display='inline'", driver.find_element_by_xpath( '//*[@id="g-recaptcha-response"]' ),)
Then execute the script to insert the response into the text box:
driver.execute_script('document.getElementById("g-recaptcha-response").innerHTML = "%s"' % captcha_response)
After that press your submit button and you'll see your success.