Documentation
¶
Overview ¶
Package fetch reads one public web page per call: public addresses only, no crawling, no cookies. By default a client with a Chrome TLS fingerprint goes first, with a plain Go client as backup for its library's own TLS or protocol errors; robots.txt is consulted only when asked.
Index ¶
- Constants
- func Blocked(status int, body []byte) bool
- func Challenge(status int, body []byte) bool
- func Clip(s string, n int) string
- func DialContext(ctx context.Context, network, address string) (net.Conn, error)
- func EmptyRendered(dom []byte) bool
- func NeedsJS(body []byte, contentType string) bool
- func Text(body []byte, contentType string) string
- type Attempt
- type Fetcher
- type Page
Constants ¶
const ( ClientChromeLike = "chrome_like" ClientPlain = "plain" // the plain client as the first step (Impersonate off or fallback) ClientPlainBackup = "plain_backup" // the plain client after the Chrome-like client errored )
Clients, the steps of the ladder that produced an attempt.
const ( OutcomeOK = "ok" OutcomeRefused = "refused" // HTTP 403 or 429 OutcomeChallenge = "challenge" // HTTP 503 or a bot-challenge page OutcomeNeedsJS = "needs_js" // an HTML shell whose content only JavaScript would render OutcomeTimeout = "timeout" // the client's time budget ran out OutcomeError = "error" // network error, other HTTP status, address refusal OutcomeDisallowed = "disallowed" // robots.txt, only with RespectRobots )
Outcomes of one attempt.
const ( ImpersonateAlways = "always" // Chrome-like first, plain backup on its TLS or protocol errors (default) ImpersonateFallback = "fallback" // plain first, Chrome-like when the plain client is refused or challenged ImpersonateOff = "off" // plain client only )
Impersonation modes.
const ( DefaultUserAgent = "refetch" DefaultRobotsAgent = "refetch" DefaultTimeout = 20 * time.Second MaxBytes = 2 << 20 )
Defaults for the zero Fetcher.
Variables ¶
This section is empty.
Functions ¶
func Challenge ¶
Challenge reports whether a response is a bot challenge rather than the page: HTTP 503, HTTP 202 (AWS WAF answers a GET with an empty 202 and a challenge script), or a short page carrying a challenge marker.
func DialContext ¶
DialContext dials the way both clients do: public addresses only, checked after DNS resolution. The headless Chrome step's proxy dials with it.
func EmptyRendered ¶
EmptyRendered reports whether a DOM from headless Chrome has next to no text. Unlike NeedsJS it ignores scripts and mount points, which stay.
Types ¶
type Attempt ¶
type Attempt struct {
URL, Host, Client, Outcome string
Status int
Bytes int
Duration time.Duration
Err string
}
Attempt is one client's try at a page, reported to Fetcher.Record.
type Fetcher ¶
type Fetcher struct {
Impersonate string // ImpersonateAlways when empty
RespectRobots bool // consult robots.txt before fetching
UserAgent string // the plain client's User-Agent; DefaultUserAgent when empty
RobotsAgent string // the robots.txt agent name; DefaultRobotsAgent when empty
Timeout time.Duration // per client; DefaultTimeout when zero
Record func(Attempt) // called after every attempt, if set
// contains filtered or unexported fields
}
Fetcher gets pages. The zero value impersonates Chrome first and ignores robots.txt.