Documentation
¶
Overview ¶
Package scrape fetches individual pages with reusable HTTP and browser sessions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("scrape: client is closed")
ErrClosed indicates that the client has been closed.
var ErrSessionLost = errors.New("scrape: browser session lost")
ErrSessionLost indicates that the browser lost the client's session.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client owns a private cookie session. It is safe for concurrent use and admits one fetch at a time. Create a client with New.
func (*Client) ClearCookies ¶
ClearCookies removes all cookies from the client's session across all hosts. It leaves the proxy and browser local storage in place. It waits for the current fetch to finish. If ctx expires during a browser command, the browser session becomes unusable and fetches and clears return ErrSessionLost until the session is reset. Sites can set fresh cookies through subsequent requests, including requests from browser service workers.
func (*Client) Close ¶
Close cancels active and waiting operations and releases the current session. Calling Close again returns the same result.
func (*Client) Fetch ¶
Fetch performs a GET. HTTP status codes, including non-2xx codes, are returned in the result. If a later step fails, Fetch returns any available response alongside the error. For downloads, use HTTP mode. JavaScript mode returns a navigation error when Chromium treats a response as a download.
func (*Client) ResetSession ¶
ResetSession replaces the client's session. It starts with a fresh cookie jar in HTTP mode or fresh browser storage in JavaScript mode, and selects the next configured proxy. It waits for any active fetch before replacing the session, and can recover a lost browser session.
Cancellation before replacement leaves the previous session in place. If cancellation or a cleanup error occurs while closing the previous session, the new session remains active.
type FetchOption ¶
type FetchOption func(*fetchConfig) error
FetchOption configures a single fetch.
func WaitFor ¶
func WaitFor(selector string) FetchOption
WaitFor waits for a visible CSS selector in JavaScript mode before taking the HTML snapshot.
func WithOutputs ¶ added in v1.6.0
func WithOutputs(outputs ...Output) FetchOption
WithOutputs requests additional representations from the same navigation. Output names must be unique across all options for a fetch.
type Option ¶
type Option func(*clientConfig) error
Option configures a client.
func WithJS ¶
func WithJS() Option
WithJS uses a headless Chromium session. Install the matching Playwright driver and Chromium browser before creating the client.
func WithProxies ¶
WithProxies supplies proxy endpoints. New clients select successive endpoints from the list. ResetSession advances the client's selection, and fetches keep using the selected endpoint between resets.
func WithTimeout ¶
WithTimeout sets the time budget for a fetch, including waiting for the client to become available. The default is 30 seconds.
type Output ¶ added in v1.6.0
type Output struct {
// contains filtered or unexported fields
}
Output describes a representation to produce during Fetch.
type Result ¶
type Result struct {
Response scrapemate.Response
// contains filtered or unexported fields
}
Result holds the original navigation response and the page's HTML representation.
func (*Result) Artifact ¶ added in v1.6.0
Artifact returns a requested output if its conversion succeeded.