captcha

package
v0.0.23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package captcha provides CAPTCHA detection and solving for the Foxhound scraping framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CapSolver

type CapSolver struct {
	// contains filtered or unexported fields
}

CapSolver implements Solver using the CapSolver API.

func NewCapSolver

func NewCapSolver(apiKey string) *CapSolver

NewCapSolver creates a CapSolver that calls the production CapSolver API.

func NewCapSolverWithEndpoint

func NewCapSolverWithEndpoint(apiKey, endpoint string) *CapSolver

NewCapSolverWithEndpoint creates a CapSolver with a custom base URL. This is used in tests to point at a mock server.

func (*CapSolver) Balance

func (s *CapSolver) Balance(ctx context.Context) (float64, error)

Balance returns the CapSolver account balance in USD.

func (*CapSolver) Solve

func (s *CapSolver) Solve(ctx context.Context, challenge *DetectResult) (*Solution, error)

Solve submits the challenge to CapSolver and polls until resolved.

type CaptchaType

type CaptchaType string

CaptchaType identifies the type of CAPTCHA detected.

const (
	// CaptchaNone means no CAPTCHA was detected.
	CaptchaNone CaptchaType = ""
	// CaptchaCloudflare is a Cloudflare Turnstile challenge.
	CaptchaCloudflare CaptchaType = "cloudflare_turnstile"
	// CaptchaRecaptcha is a Google reCAPTCHA challenge.
	CaptchaRecaptcha CaptchaType = "recaptcha"
	// CaptchaHCaptcha is an hCaptcha challenge.
	CaptchaHCaptcha CaptchaType = "hcaptcha"
	// CaptchaGeeTest is a GeeTest challenge.
	CaptchaGeeTest CaptchaType = "geetest"
	// CaptchaUnknown is an unrecognised CAPTCHA challenge.
	CaptchaUnknown CaptchaType = "unknown"
	// CaptchaSoftBlock is a 200 OK response whose body signals "access denied".
	CaptchaSoftBlock CaptchaType = "soft_block"
	// CaptchaEmptyTrap is a 200 OK response with suspiciously minimal content.
	CaptchaEmptyTrap CaptchaType = "empty_trap"
	// CaptchaLoginWall is a redirect to a login page used to gate content.
	CaptchaLoginWall CaptchaType = "login_wall"
	// CaptchaJSChallenge is a JS-only challenge page (e.g. Akamai) that has no
	// CAPTCHA widget but blocks until the browser executes challenge JS.
	CaptchaJSChallenge CaptchaType = "js_challenge"
)

type DetectResult

type DetectResult struct {
	// Type is the kind of CAPTCHA found.
	Type CaptchaType
	// SiteKey is the site key extracted from the page (may be empty).
	SiteKey string
	// PageURL is the URL of the page that triggered detection.
	PageURL string
}

DetectResult describes a detected CAPTCHA.

func Detect

func Detect(resp *foxhound.Response) *DetectResult

Detect analyses a Response to determine whether it contains a CAPTCHA challenge and, if so, which kind. It also attempts to extract the site key.

type NopeCHA

type NopeCHA struct {
	// contains filtered or unexported fields
}

NopeCHA implements Solver using the NopeCHA Token API. Token API is browserless: submit sitekey + URL, get a solved token back. Supports hCaptcha, reCAPTCHA v2/v3, and Cloudflare Turnstile.

func NewNopeCHA

func NewNopeCHA(apiKey string) *NopeCHA

NewNopeCHA creates a NopeCHA solver that calls the production API.

func NewNopeCHAWithEndpoint

func NewNopeCHAWithEndpoint(apiKey, endpoint string) *NopeCHA

NewNopeCHAWithEndpoint creates a NopeCHA solver with a custom base URL (for tests).

func (*NopeCHA) Balance

func (s *NopeCHA) Balance(ctx context.Context) (float64, error)

Balance returns the remaining credits from the NopeCHA account.

func (*NopeCHA) Solve

func (s *NopeCHA) Solve(ctx context.Context, challenge *DetectResult) (*Solution, error)

Solve submits a token challenge and polls until resolved.

type Solution

type Solution struct {
	// Token is the solved CAPTCHA response string.
	Token string
	// Type is the CAPTCHA type that was solved.
	Type CaptchaType
}

Solution contains a solved CAPTCHA token ready to be submitted to the target site.

type Solver

type Solver interface {
	// Solve submits the challenge to the solving service and returns the token.
	Solve(ctx context.Context, challenge *DetectResult) (*Solution, error)
	// Balance returns the solver account balance in USD.
	Balance(ctx context.Context) (float64, error)
}

Solver solves CAPTCHA challenges using an external service.

type TurnstileHandler

type TurnstileHandler struct {
	// contains filtered or unexported fields
}

TurnstileHandler is a specialised handler for Cloudflare Turnstile challenges. Turnstile is often invisible/behavioural so it delegates directly to the configured fallback solver (CapSolver or 2captcha).

func NewTurnstile

func NewTurnstile(fallback Solver) *TurnstileHandler

NewTurnstile creates a TurnstileHandler that uses fallback to solve challenges that cannot be bypassed behaviourally.

func (*TurnstileHandler) Handle

func (t *TurnstileHandler) Handle(ctx context.Context, challenge *DetectResult) (*Solution, error)

Handle attempts to solve a Turnstile challenge. It returns the cf-turnstile-response token on success.

type TwoCaptcha

type TwoCaptcha struct {
	// contains filtered or unexported fields
}

TwoCaptcha implements Solver using the 2captcha API.

func NewTwoCaptcha

func NewTwoCaptcha(apiKey string) *TwoCaptcha

NewTwoCaptcha creates a TwoCaptcha that calls the production 2captcha API.

func NewTwoCaptchaWithEndpoint

func NewTwoCaptchaWithEndpoint(apiKey, endpoint string) *TwoCaptcha

NewTwoCaptchaWithEndpoint creates a TwoCaptcha with a custom base URL. This is used in tests to point at a mock server.

func (*TwoCaptcha) Balance

func (s *TwoCaptcha) Balance(ctx context.Context) (float64, error)

Balance returns the 2captcha account balance in USD.

func (*TwoCaptcha) Solve

func (s *TwoCaptcha) Solve(ctx context.Context, challenge *DetectResult) (*Solution, error)

Solve submits the challenge to 2captcha and polls until resolved.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL