Introduction
A captcha sometimes could be annoying. It is even more annoying when you are working on automation software. A captcha, from a simple calculation, a slider captcha, HCpatcha, and ReCaptcha are not easy to be solved using automation. You may create a deep/machine learning model to solve the captcha. But, how about the training datasets? It will be bulky to work with the training datasets, or else, it will be hard. That’s why many sites use captcha to prevent automation/bot.
But, what if you have someone that would solve the captcha for you? Wouldn’t it be easier? You don’t need to think about solving the captcha and start focusing on the real problem. That’s where 2Captcha comes as a captcha solver. 2Captcha is a captcha solving software that may help you with solving captchas. 2Captcha has a varied library to work with various programming languages. So whatever languages you use, 2Captcha’s API is there for you.
In this sponsored article, you will learn how to bypass Google ReCaptcha using 2Captcha and Golang. You will also use Chromedp to automate the job. Here, I already have created a Github repository that you may want to clone.
Clone the Repository
| |
Usage
| |
Let me explain how the code works.
Main File
You may want to focus only on the main.go file because the other file is just supportive files.
Helper Function
| |
runFunccreates timeouts for the givenchromedp actionFuncrunwrapsrunFuncto help it works withchromedp actionwaitwrapsrunto make Chromedp wait for the element given as a selector inside the parameter
Captcha Solver
| |
solveRecaptcha solves your Google ReCAPTCHA using the 2Captcha Golang library which you can see the code and documentation here.
Chromedp Actions
| |
Inside the recaptchaDemoActions, you can define your targetURL as for this example is Google ReCAPTCHA demo page.
Actions Explanation
| |
Navigate to the targetURL and give it a timeout depending on your internet speed.
| |
Wait for the element that has [data-sitekey] attribute which is the Google ReCAPTCHA site key that you will pass to the solveRecaptcha function.
| |
Wait for the element where you can put the Google ReCAPTCHA solution that the solveRecaptcha function will provide.
| |
Wait for the submit button element.
| |
Fetch the data-sitekey attribute from the [data-sitekey] element, then put it on the siteKey and siteKeyOk variables.
| |
If the siteKeyOk variable returns false, it means the siteKey is not found. Otherwise, you pass it to the solveRecaptcha function along with 2Captcha's client and your targetURL. The function blocks the flow until it returns the token. And then, you set the token as the #g-recaptcha-response element’s innerText.
| |
Click the submit button right after the token is set.
| |
Wait for the .recaptcha-success element that indicates that your captcha is successfully bypassed.
Main Function
| |
To Use the 2Captcha’s services, you may need to provide the API Key. You can get the API Key by registering to the 2Captcha’s service here by using my referral link.
After you have set the 2Captcha’s client, pass it to the recaptchaDemoActions function to get your Chromedp actions. Optionally, You may set the opts on line 77 to configure your Chromedp flags. You can refer to the docs to see other options. Then, create the Chromedp context and run it. You may see the code’s output just like in the usage section.
Conclusion
After all the journey, you may find it interesting to solve the Google ReCAPTCHA automatically. You may want to use 2Captcha’s services to solve other captchas besides Google Recaptcha by referring to the docs. It is straightforward and super easy to use.
Thank you for reading!