Documentation
¶
Overview ¶
Package scrapeland is a client for the scrape.land web data extraction API.
There are two ways in, and most Go programs want the first:
- Client.HTTPClient returns a *http.Client wired to the rotating gateway. Every request it makes exits from a fresh IP. Nothing else in your code has to change — hand it to any library that accepts an *http.Client.
- Client.Fetch / Extract / Batch / Search call the data API directly and return parsed results, for when you want structured data rather than a transport.
Control parameters (country, sticky session, protocol, latency ceiling) are encoded into the proxy username, so they work through the plain transport too:
pb_live_KEY-country-us-session-job42-protocol-socks5-maxlatency-3000
Zero dependencies: standard library only.
Index ¶
- Constants
- Variables
- type APIError
- type BatchResult
- type Client
- func (c *Client) Account(ctx context.Context) (map[string]any, error)
- func (c *Client) Batch(ctx context.Context, urls []string, o *Options) (*BatchResult, error)
- func (c *Client) Capabilities(ctx context.Context) (map[string]any, error)
- func (c *Client) Extract(ctx context.Context, target string, fields map[string]any, o *Options) (*Result, error)
- func (c *Client) Fetch(ctx context.Context, target string, o *Options) (*Result, error)
- func (c *Client) GetJob(ctx context.Context, id string) (*Job, error)
- func (c *Client) HTTPClient(o *Options) *http.Client
- func (c *Client) Jobs(ctx context.Context, limit int) ([]Job, error)
- func (c *Client) ProxyURL(o *Options) (*url.URL, error)
- func (c *Client) ProxyUsername(o *Options) string
- func (c *Client) Search(ctx context.Context, query string, o *Options) (*SearchResult, error)
- func (c *Client) SubmitJob(ctx context.Context, jobType string, params map[string]any) (*Job, error)
- type Job
- type Option
- type Options
- type Result
- type SearchResult
Constants ¶
const ( // DefaultGateway is the forward proxy. Port 8080 is the long-standing // endpoint; 443 also serves the proxy for networks that filter 8080. DefaultGateway = "http://gateway.scrape.land:8080" // DefaultAPIBase is the data API — a different host from the proxy. DefaultAPIBase = "https://scrape.land" )
Variables ¶
var ErrNoAPIKey = errors.New("scrapeland: api key required (pass it or set $SCRAPELAND_API_KEY)")
ErrNoAPIKey is returned by New when no key was passed and none is in the environment.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
APIError is a non-2xx response from the data API. Status is the HTTP code; Body is the (truncated) response body, which usually carries a JSON message.
type BatchResult ¶
type BatchResult struct {
Results []Result `json:"results"`
}
BatchResult is the response from Batch: one entry per requested URL, in order.
type Client ¶
type Client struct {
APIKey string
Gateway string
APIBase string
// Defaults applied to every request; per-request Options override them.
Country string
Session string
Protocol string
MaxLatencyMS int
// Retries counts EXTRA attempts after the first (default 2). Backoff is the
// base delay, doubled per attempt.
Retries int
Backoff time.Duration
// HTTP is used for data API calls. It is NOT proxied — the data API is a
// normal HTTPS endpoint. Use HTTPClient for proxied traffic.
HTTP *http.Client
}
Client talks to the scrape.land gateway and data API. The zero value is not usable — construct it with New.
func New ¶
New builds a Client. apiKey falls back to $SCRAPELAND_API_KEY. Gateway and API base fall back to $SCRAPELAND_GATEWAY / $SCRAPELAND_API_BASE, then the public endpoints.
func (*Client) Capabilities ¶
Capabilities reports what this deployment supports. No API key required.
func (*Client) Extract ¶
func (c *Client) Extract(ctx context.Context, target string, fields map[string]any, o *Options) (*Result, error)
Extract pulls structured data from a page. fields maps a name to a CSS selector, an XPath string (leading "/"), or an object with css/xpath/attr/all. Pass nil fields and set Options.Prompt to use AI extraction instead.
func (*Client) HTTPClient ¶
HTTPClient returns an *http.Client whose every request exits from a fresh IP. Pass nil for o to use the client defaults.
c, _ := scrapeland.New(key)
res, err := c.HTTPClient(nil).Get("https://api.ipify.org")
Each call builds a fresh Transport, because the control parameters live in the proxy credentials — sharing one across different Options would silently apply the first caller's country and session to everyone else.
func (*Client) ProxyUsername ¶
ProxyUsername builds the proxy username: the API key plus control parameters. Per-request values in o override the client defaults.
type Job ¶
type Job struct {
ID string `json:"id"`
Type string `json:"type"`
Status string `json:"status"`
Result json.RawMessage `json:"result,omitempty"`
Error string `json:"error,omitempty"`
}
Job is an async job record.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithAPIBase ¶
WithAPIBase overrides the data API base URL.
func WithCountry ¶
WithCountry sets a default exit country (ISO code, e.g. "us").
func WithHTTPClient ¶
WithHTTPClient supplies the client used for data API calls (timeouts, tracing).
func WithMaxLatency ¶
WithMaxLatency only uses upstreams faster than the given milliseconds.
func WithProtocol ¶
WithProtocol restricts the upstream protocol ("http", "https", "socks5").
func WithRetries ¶
WithRetries sets how many EXTRA attempts follow a failure.
func WithSession ¶
WithSession sets a default sticky-session id (same exit IP across requests).
type Options ¶
type Options struct {
Format string `json:"format,omitempty"` // "html" (default), "text", "markdown", "raw"
Country string `json:"country,omitempty"`
Session string `json:"session,omitempty"`
Protocol string `json:"protocol,omitempty"`
MaxLatency int `json:"max_latency,omitempty"`
Render bool `json:"render,omitempty"`
Device string `json:"device,omitempty"`
BlockResources bool `json:"block_resources,omitempty"`
Fingerprint bool `json:"fingerprint,omitempty"`
WaitFor string `json:"wait_for,omitempty"`
Headers bool `json:"headers,omitempty"`
Screenshot bool `json:"screenshot,omitempty"`
FullPage bool `json:"full_page,omitempty"`
SendHeaders map[string]string `json:"send_headers,omitempty"`
Cookies string `json:"cookies,omitempty"`
Method string `json:"method,omitempty"`
Body string `json:"body,omitempty"`
Actions []any `json:"actions,omitempty"`
Metadata bool `json:"metadata,omitempty"`
Links bool `json:"links,omitempty"`
// Extraction. Fields holds CSS/XPath selectors; Prompt drives AI extraction.
Fields map[string]any `json:"fields,omitempty"`
Prompt string `json:"prompt,omitempty"`
Schema any `json:"schema,omitempty"`
Model string `json:"model,omitempty"`
ExtractType string `json:"extract_type,omitempty"`
// Search only.
Count int `json:"count,omitempty"`
}
Options are the per-request knobs shared by Fetch, Extract, Batch and Search. Every field is optional; the zero value means "use the client default, or the server default". It doubles as the request payload, which is why the json tags matter as much as the field names.
type Result ¶
type Result struct {
URL string `json:"url"`
Status int `json:"status"`
HTML string `json:"html,omitempty"`
Text string `json:"text,omitempty"`
Markdown string `json:"markdown,omitempty"`
Base64 string `json:"base64,omitempty"`
ContentType string `json:"content_type,omitempty"`
Screenshot string `json:"screenshot,omitempty"`
Data map[string]any `json:"data,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Links []string `json:"links,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
Error string `json:"error,omitempty"`
}
Result is one fetched page. Which body field is populated depends on Format.