Expand description
Official Rust SDK for the webscrape.ai API.
Covers the public API-key surface: Client::scrape, Client::smartscraper,
and the SmartBrowse namespace (dispatch a recipe run, poll it, wait for
completion, read usage). See https://webscrape.ai/docs for API docs.
§Quick start
use webscrape_ai::{Client, ScrapeRequest};
// Reads WEBSCRAPE_API_KEY from the environment.
let client = Client::from_env()?;
let resp = client
.scrape(ScrapeRequest::new("https://example.com").clean(true))
.await?;
println!("credits used: {:?}", resp.credits_used);
println!("markdown: {:?}", resp.data.html);§Structured extraction
use webscrape_ai::{Client, SmartScraperRequest};
use serde_json::json;
let client = Client::new("wsg_live_...")?;
let resp = client
.smartscraper(
SmartScraperRequest::new(
"https://news.ycombinator.com",
"Extract the front-page stories with title, url, and score.",
)
.output_schema(json!({
"type": "object",
"properties": { "stories": { "type": "array" } }
})),
)
.await?;
// `data.result` is a serde_json::Value; decode it into your own type.
let value = resp.data.result;
println!("{value:?}");§Error handling
Every method returns Result<T>. Failures surface as
Error, which distinguishes API errors (Error::Api carrying an
ApiError you branch on via ApiError::kind) from transport, timeout,
and wait-helper failures.
Modules§
- blocking
- Synchronous client, enabled by the
blockingcargo feature. Mirrors the asyncClientsurface, wrappingreqwest::blockingand usingstd::thread::sleepfor backoff and the wait helper.
Structs§
- ApiError
- A structured API error decoded from the response envelope.
- Client
- Async webscrape.ai API client. Cheap to
Clone(reference-counted). - Client
Builder - Builder for
Client. - Link
Info - An outbound link from
ScrapeData::links. - Page
Metadata - Page metadata from
ScrapeData::metadata(HTML only; null for PDFs). - Response
- A successful (
completed/queued) response envelope with typeddata. - Scrape
Data datafor a successfulClient::scrapecall.- Scrape
Request - Request body for
Client::scrape. - Smart
Browse - The SmartBrowse method namespace, obtained via
Client::smartbrowse. - Smart
Browse Dispatch datareturned when dispatching a SmartBrowse run (HTTP 202queued).- Smart
Browse Last Run - Summary of the account’s most recent run, from
SmartBrowseUsage. - Smart
Browse Run datareturned when polling a SmartBrowse run.- Smart
Browse Usage dataforSmartBrowse::usage— plan caps and rolling-30-day usage.- Smart
Scraper Data datafor a successfulClient::smartscrapercall.- Smart
Scraper Request - Request body for
Client::smartscraper. - Wait
Options - Options for
SmartBrowse::wait_for_runandSmartBrowse::run_and_wait.
Enums§
- Detail
Level - How exhaustively
SmartScraperRequestshould populate the result. - Error
- Top-level error returned by every SDK method.
- Error
Code - Stable API error code. Unknown codes decode to
ErrorCode::Unknownwith the raw string preserved. - Page
Complexity - Page-complexity hint for
SmartScraperRequest. - Parse
Mode - Cleaner mode used when
clean: true. - RunStatus
- SmartBrowse run lifecycle state. Unknown values decode to
RunStatus::Unknownrather than failing.
Constants§
- API_
KEY_ ENV - Environment variable consulted for the API key when none is passed explicitly.
- DEFAULT_
BASE_ URL - Default production base URL (
https://api.webscrape.ai/v1). - VERSION
- SDK version, sourced from
CARGO_PKG_VERSIONand used in theUser-Agent.
Type Aliases§
- Result
- Convenience alias for
Result<T, webscrape_ai::Error>.