This article is for those of you who are doing reg tools, registering multiple accounts on the website. Or maybe it’s crawling data and getting caught in captcha without knowing how to solve it. When caught in captcha, you have to spend 3 -5 seconds to solve them. For normal users, it’s okay, but for tool users to create from a few hundred to a few thousand accounts or requests, this is not a solution. So in this article, I will show you how to solve Google captcha with Python super easy.
CAPTCHA stands for Completely Automated Public Turing test to tell Computers and Humans Apart. A CAPTCHA is a tool used to distinguish between real users and computers, such as bots. CAPTCHAs present challenges that are difficult for computers to do but relatively easy for humans. For example, identify letters or choose a traffic light in a hard-to-see photo.
CAPTCHA works by providing information to real users to decode. Traditional CAPTCHAs provide distorted or overlapping letters and numbers for user confirmation. Distorted letters make it difficult for bots to decipher and prevent access until the captcha is verified.
Since CAPTCHA was introduced, bots using machine learning have been developed. These bots are better able to verify traditional CAPTCHAs using algorithms that are trained many times over. As a result of this development, newer CAPTCHA methods based on more complex tests are born. For example, reCAPTCHA requires clicking on a specific area and waiting until the solve is successful.
Get AzCaptcha’s KeyAPI
Step 1: First, you go to AZcaptcha website and register a new account. Each newly created account will be given $0.02, you can solve 10 to 20 times depending on the type of Captcha. Note: I recommend that you use a temporary email to create an account. If you run out of money, just create another new account.
Step 2: On the dashboard page, you will see the keyAPI on the right side, copy that keyAPI.
How to bypass Google Captcha with python
First, you need to make sure your system has full python, pip. Then install 2 more packages request and bs. I will also use the site reCaptcha demo as an example in this article.
You press F12 search for keywords sitekey equal Ctrl + F.
As you can see above, the div tag has the class “g-recaptcha” and the data-sitekey is “6Le-wvk……”. In python there is a library that helps us to disassemble the html and get the data-sitekey inside the div tag bs4.
from bs4 import BeautifulSoup import requests from time import sleep URL = 'https://www.google.com/recaptcha/api2/demo' def get_siteKey(url): response = requests.get(url) soup = BeautifulSoup(response.text, "html.parser") g_recaptcha = soup.find_all('div', {'class' : 'g-recaptcha'}) sitekey = g_recaptcha[0].get('data-sitekey') return sitekey
Next is the solve_Captcha function used to solve the captcha. You replace {keyAPI} with the API you get in the AZcaptcha page. After sending the request to solve the captcha successfully, the server will send the id of your captcha. This ID is used to identify the captcha that you send to the server. You should let the program stop for about 30 seconds for the server to solve the captcha.
def solve_Captcha(REQ_URL, url, keyAPI, sitekey): payload = { 'key': keyAPI, 'method': 'userrecaptcha', 'googlekey': sitekey, 'pageurl': url, 'here': 'now' } response = requests.post(REQ_URL, data=payload) return response BASE_URL = 'http://azcaptcha.com' REQ_URL = BASE_URL + '/in.php' RES_URL = BASE_URL + '/res.php' keyAPI = '{keyAPI}' response = solve_Captcha(REQ_URL, URL, keyAPI, siteKey) if response.status_code == 200: print('Solving captcha...') id = response.text.split('|')[1] sleep(30)
Next, you use the get_gCaptcha function to check if the captcha has been solved. If done, we will get gCaptcha, and if not done, we continue to call the get_gCaptcha function again to check.
def get_gCaptcha(RES_URL, keyAPI, id): payload = { 'key': keyAPI, 'action': 'get', 'id': id, } response = requests.post(RES_URL, data = payload) if response.text == 'CAPCHA_NOT_READY': print('CAPTCHA NOT READY. Try again in 30s.') sleep(30) gCaptcha = get_gCaptcha(RES_URL, keyAPI, id) return gCaptcha if 'OK' in response.text: gCaptcha = response.text.split('|')[1] return gCaptcha
Full code:
from bs4 import BeautifulSoup import requests from time import sleep URL = 'https://www.google.com/recaptcha/api2/demo' def get_siteKey(url): response = requests.get(url) soup = BeautifulSoup(response.text, "html.parser") g_recaptcha = soup.find_all('div', {'class' : 'g-recaptcha'}) sitekey = g_recaptcha[0].get('data-sitekey') return sitekey siteKey = get_siteKey(URL) print(siteKey) def solve_Captcha(REQ_URL, url, keyAPI, sitekey): payload = { 'key': keyAPI, 'method': 'userrecaptcha', 'googlekey': sitekey, 'pageurl': url, 'here': 'now' } response = requests.post(REQ_URL, data=payload) return response def get_gCaptcha(RES_URL, keyAPI, id): payload = { 'key': keyAPI, 'action': 'get', 'id': id, } response = requests.post(RES_URL, data = payload) if response.text == 'CAPCHA_NOT_READY': print('CAPTCHA NOT READY. Try again in 30s.') sleep(30) gCaptcha = get_gCaptcha(RES_URL, keyAPI, id) return gCaptcha if 'OK' in response.text: gCaptcha = response.text.split('|')[1] return gCaptcha BASE_URL = 'http://azcaptcha.com' REQ_URL = BASE_URL + '/in.php' RES_URL = BASE_URL + '/res.php' keyAPI = '{keyAPI}' response = solve_Captcha(REQ_URL, URL, keyAPI, siteKey) if 'OK' in response.text: print('Solving captcha...') id = response.text.split('|')[1] sleep(30) gCaptcha = get_gCaptcha(RES_URL, keyAPI, id) print(gCaptcha) else: print(response.text)
You have successfully obtained the gCaptcha code. Next, you just need to replace the gCaptcha code on the page you want to pass the captcha by using the excute javascript command below:
document.getElementById("g-recaptcha-response").innerHTML="{gCaptcha}";
That’s it, then. Good luck.