In order to resolve ReCaptcha, we have to use some resolving captcha service and integrate it into our program. This article will guide you how to integrate it into Python/Selenium program
Resolving captcha service
There are many resolving captcha services. In this session, I suggest 3 providers and rate them following my experience.
ReCaptcha with callback
If you have a situation with:
- Invisible ReCaptcha v2, where there is no named callback function defined anywhere (not mentioned in the HTML, nor present in the js source code).
- No form submit button anywhere (not visible or invisible, nor dynamically generated by js).
- You want to use a resolving captcha service to automatically solve it and proceed to post the form.
If that’s your case, then follow the steps below:
1. Using Chrome/Firefox Dev Tools -> Console
- Manually inspect the existing js object structure by typing:
- This is an array of all the recaptcha objects currently created on the page. More often than not, there will be only one. So, that’s index .
Manually inspect the objects of the above array. In my situation there was only one:
Still using the Console, inspect & try to find the object ___grecaptcha_cfg.clients.Gq.X
NOTE: “Gq.X” may be different in your case. For example, in 2Captcha’s API documentation they are referring to it as “aa.l”.
Traverse the object tree and you’ll know that you found it when you see the property “sitekey” and the function “callback” listed under it in the tree.
- Take a note of the object name of your case (in my case it was “Gq.X”).
- Take note of the sitekey string.
2. Contact a resolving captcha service to resolve the 2captcha
Below is sample Python/anti-captcha code to resolve ReCaptcha
3. Set the response to textarea
In the HTML source code of the target webpage search and find the hidden <textarea> element which has “display: none” & id/name=”g-recaptcha-response”.
Type/Inject into its innerHTML the 2Captcha response token text (from step 2).
DON’T forget to replace:
“Gq.X” with the actual object name of your case (see step 1.3)
2CAPTCHA_RESPONSE is the 2Captcha response token text (from step 3)
5. Manually submit the main form of the target webpage, or click the main button to proceed to the next page (if there’s no submit button).
At this stage the page will get the solved captcha correctly and continue normally (given that you have provided valid data to any other form field that was required by this form/webpage).
PS: Sometimes, we may insert an HTML button into the webpage to call the callback function. (I met this while trying to resolve ReCaptcha on Walmart.com
I am Tuan from Vietnam. I am a programmer Freelancer at web scraping, web automation, Python scripting. I have worked for 7+ years in these fields.