Captcha Tools (Go)
Go package to help solve captchas with Capmonster, 2Captcha and Anticaptcha API's!
2.0.0
What's new
- Get Balance Support
- Proxy Support
- User Agent Support
- Text image captcha support
- Refund support / Report answers support
- AntiCaptcha SoftID support
Breaking Changes
- Changed the type of site from type
int
to type site
- This affects the
NewHarvester()
param
- Returns a
CaptchaAnswer
object rather than just the captcha token - Made captchas their own type
Upgrading to 2.0.0
- When passing in the config, instead of manually declaring the
CaptchaType
field, use a preset type such as captchatools.ImageCaptcha
- Instead of a captcha token being returned, a
CaptchaAnswer
is returned. To get the captcha answer, you must call the .Token
field from the returned answer. See Examples.
Install
go get github.com/Matthew17-21/Captcha-Tools/captchatools-go
To update:
go get -u github.com/Matthew17-21/Captcha-Tools/captchatools-go
How to use
Basic usage
package main
import (
"fmt"
captchatools "github.com/Matthew17-21/Captcha-Tools/captchatools-go"
)
func main() {
solver, err := captchatools.NewHarvester(captchatools.CapmonsterSite, &captchatools.Config{
Api_key: "ENTER YOUR API KEY HERE",
Sitekey: "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
CaptchaURL: "https://www.google.com/recaptcha/api2/demo",
CaptchaType: captchatools.V2Captcha,
})
if err != nil {
...
}
answer, err := solver.GetToken()
if err != nil {
switch err {
case captchatools.ErrBanned:
...
case captchatools.ErrAddionalDataMissing:
...
}
}
fmt.Println("Captcha ID:", answer.Id())
fmt.Println("Captcha token:", answer.Token)
answer.Report(true)
answer.Report(false)
}
NewHarvester() Parameters:
Parameter | Required | Type | Description |
---|
solving_site | true | int (iota) | The captcha solving site that will be used. Refer to the site IDs. Alternatively, you can use shortcuts such as captchatools.AnticaptchaSite |
Config | true | captchatools.Config | Configurations for the captchas you are solving. |
Config struct fields:
Field | Required | Type | Description |
---|
Api_key | true | String | The API Key for the captcha solving site |
Sitekey | true | String | Sitekey from the site where captcha is loaded |
CaptchaURL | true | String | URL where the captcha is located |
CaptchaType | true | captchaType | Type of captcha you are solving. See captcha types |
Action | false | String | Action that is associated with the V3 captcha. This param is only required when solving V3 captchas |
IsInvisibleCaptcha | false | bool | If the captcha is invisible or not. This param is only required when solving invisible captchas |
MinScore | false | float32 | Minimum score for v3 captchas. This param is only required when solving V3 and it needs a higher / lower score |
SoftID | false | int | 2captcha Developer ID. Developers get 10% of spendings of their software users. |
AdditionalData struct fields:
Field | Required | Type | Description |
---|
B64Img | false | String | Base64 encoded captcha image This param is only required when solving image captchas |
Proxy | false | *Proxy | Proxy to be used to solve captchas. This will make the captcha be solved from the proxy ip |
ProxyType | false | string | Type of the proxy being used. Options are: HTTP , HTTPS , SOCKS4 , SOCKS5 |
UserAgent | false | string | UserAgent that will be passed to the service and used to solve the captcha |
RQData | false | string | Custom data that is used in some implementations of hCaptcha. Most of the times, you want to set the IsInvisibleCaptcha param to true . |
Examples
Example - V2 Captcha / Basic usage
package main
import (
"fmt"
captchatools "github.com/Matthew17-21/Captcha-Tools/captchatools-go"
)
func main() {
solver, err := captchatools.NewHarvester(captchatools.CapmonsterSite, &captchatools.Config{
Api_key: "ENTER YOUR API KEY HERE",
Sitekey: "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
CaptchaURL: "https://www.google.com/recaptcha/api2/demo",
CaptchaType: captchatools.V2Captcha,
})
if err != nil {
...
}
answer, err := solver.GetToken()
if err != nil {
switch err {
case captchatools.ErrBanned:
...
case captchatools.ErrAddionalDataMissing:
...
}
}
fmt.Println("Captcha ID:", answer.Id())
fmt.Println("Captcha token:", answer.Token)
answer.Report(true)
answer.Report(false)
}
Example - V3 Captcha
func v3Example() {
solver, err := captchatools.NewHarvester(captchatools.AnticaptchaSite, &captchatools.Config{
Api_key: "ENTER YOUR API KEY HERE",
Sitekey: "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
CaptchaURL: "..........",
CaptchaType: captchatools.V3Captcha,
Action: "submit",
MinScore: 0.9,
})
if err != nil {
panic(err)
}
answer, err := solver.GetToken()
if err != nil {
switch err {
case captchatools.ErrBanned:
case captchatools.ErrAddionalDataMissing:
}
}
fmt.Println("Captcha ID:", answer.Id())
fmt.Println("Captcha token:", answer.Token)
answer.Report(true)
answer.Report(false)
}
Example - Image captcha
package main
import (
"fmt"
captchatools "github.com/Matthew17-21/Captcha-Tools/captchatools-go"
)
func image_captcha() {
solver, err := captchatools.NewHarvester(captchatools.CapmonsterSite, &captchatools.Config{
Api_key: "ENTER YOUR API KEY HERE",
CaptchaType: captchatools.ImageCaptcha,
})
if err != nil {
panic(err)
}
answer, err := solver.GetToken(&captchatools.AdditionalData{
B64Img: "BASE64_ENCODED_IMAGE",
})
if err != nil {
switch err {
case captchatools.ErrBanned:
case captchatools.ErrAddionalDataMissing:
}
}
fmt.Println("Captcha ID:", answer.Id())
fmt.Println("Captcha token:", answer.Token)
answer.Report(true)
answer.Report(false)
}
Example - Additional captcha data
package main
import (
"fmt"
captchatools "github.com/Matthew17-21/Captcha-Tools/captchatools-go"
)
func addtional_data() {
solver, err := captchatools.NewHarvester(captchatools.CapmonsterSite, &captchatools.Config{
Api_key: "ENTER YOUR API KEY HERE",
Sitekey: "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
CaptchaURL: "https://www.google.com/recaptcha/api2/demo",
CaptchaType: captchatools.V2Captcha,
})
if err != nil {
panic(err)
}
proxy, err := captchatools.NewProxy("IP:PORT:USER:PASS")
answer, err := solver.GetToken(&captchatools.AdditionalData{
B64Img: "BASE64_ENCODED_IMAGE",
Proxy: proxy,
ProxyType: "http",
UserAgent: "SOME_USER_AGENT",
})
if err != nil {
switch err {
case captchatools.ErrBanned:
case captchatools.ErrAddionalDataMissing:
}
}
fmt.Println("Captcha ID:", answer.Id())
fmt.Println("Captcha token:", answer.Token)
answer.Report(true)
answer.Report(false)
}
Supported Sites
Site-Specific Support:
Captcha Type | 2Captcha | Anticaptcha | Capmonster | Capsolver | CaptchaAI |
---|
Recaptcha V2 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Recaptcha V3 | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Hcaptcha | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
HcaptchaTurbo | :x: | :x: | :x: | :white_check_mark: | :x: |
Image Captcha | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Cloudflare Turnstile | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: |
Funcaptcha | :x: | :x: | :x: | :x: | :x: |
GeeTest | :x: | :x: | :x: | :x: | :x: |
Amazon WAF | :x: | :x: | :x: | :x: | :x: |
Recommendations
- For 2Captcha, don't run more than 60 tasks per API key.
- Handle errors appropriately.
- If a
ErrNoBalance
is thrown, tasks should stop. Some sites will temporarily ban IP's if constant requests come in.
Errors
Errors | Returned When |
---|
ErrNoBalance | Balance is below 0 for captcha solving site |
ErrWrongAPIKey | Incorrect API Key for captcha solving site |
ErrWrongSitekey | Incorrect sitekey |
ErrIncorrectCapType | Incorrectly chose a captcha type. When initializing a new harvester. Refer to the captcha types |
ErrNoHarvester | When the user did not / incorrectly chose a captcha harvester. Refer to the "how to use" guide |
Error Handling
package main
import (
"fmt"
captchatools "github.com/Matthew17-21/Captcha-Tools/captchatools-go"
)
func main() {
solver, err := captchatools.NewHarvester(captchatools.CapmonsterSite, &captchatools.Config{
Api_key: "ENTER YOUR API KEY HERE",
Sitekey: "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
CaptchaURL: "https://www.google.com/recaptcha/api2/demo",
CaptchaType: captchatools.V2Captcha,
})
if err != nil {
...
}
answer, err := solver.GetToken()
if err != nil {
switch err {
case captchatools.ErrBanned:
...
case captchatools.ErrAddionalDataMissing:
...
}
}
}
TODOs