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
Let me explain how the code works.
You may want to focus only on the
main.go file because the other file is just supportive files.
runFunccreates timeouts for the given
runFuncto help it works with
runto make Chromedp wait for the element given as a selector inside the parameter
solveRecaptcha solves your Google ReCAPTCHA using the 2Captcha Golang library which you can see the code and documentation here.
recaptchaDemoActions, you can define your
targetURL as for this example is Google ReCAPTCHA demo page.
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
Wait for the element where you can put the Google ReCAPTCHA solution that the
solveRecaptcha function will provide.
Wait for the submit button element.
data-sitekey attribute from the
[data-sitekey] element, then put it on 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
Click the submit button right after the
token is set.
Wait for the
.recaptcha-success element that indicates that your captcha is successfully bypassed.
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.
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!