Golang module for auto resolve google recaptcha using rucaptcha
API.
It is a few steps for resolve captcha:
- Find
data-sitekey
attribute in HTML page - Wait resolving the captcha
- Put value to
h-captcha-response
andg-recaptcha-response
- Submit hcaptcha form
- Use same Cookie and User-Agent headers for all future requests
Check example directory for full example
hcaptcha := grucaptcha.NewHcaptcha(api.RuCaptchaKey)
params := grucaptcha.HCaptchaParams{
SiteKey: siteKey,
PageUrl: uri,
}
ch, err := hcaptcha.Resolve(params)
if err != nil {
log.Fatalln(time.Now().Format(time.StampMicro), "[ERR] Rucaptcha response", err)
}
var res grucaptcha.RuCaptchaResult
select {
case res = <-ch:
case <-time.After(time.Minute):
log.Fatalln(time.Now().Format(time.StampMicro), "[ERR] Captcha resolve timeout")
}
if res.Result == "" {
log.Fatalln(time.Now().Format(time.StampMicro), "[ERR] Rucaptcha empty result", res)
}
It is very similar to hcaptcha.
- Find
data-sitekey
attribute in HTML page - Wait resolving the captcha
- Put value to
g-recaptcha-response
- Submit recaptcha form
- Use same Cookie and User-Agent headers for all future requests
Check example folder for more detailed example.
rucaptcha := grucaptcha.NewRecaptcha("<your_api_key>")
captchaParams := grucaptcha.ReCaptchaV2Params{
GoogleKey: "<data-sitekey attribute>",
PageUrl: "https://full-url.com/auth",
}
resultChan, err := rucaptcha.Resolve(captchaParams)
if err != nil {
panic(err)
}
results := <-resultChan
//Example for selenium
//Insert resolved captcha string into the hidden textarea. And submit the form
script := fmt.Sprintf(
`document.getElementById("g-recaptcha-response").value="%s"`,
results.Result)
wd.ExecuteScript(script, nil)