Install
Try it without a key
scrape, search, map and parse work without a key, within a small free allowance. Every other method throws a StophyError with the code apiKeyRequired.
Use an API key
Get a key at stophy.dev/signup. Set it asSTOPHY_API_KEY, or pass it in:
new Stophy("st_...") works too.
Each method sends one call to the Stophy API and returns its JSON as is. scrape returns { success, data }, and map returns { success, links }.
Read a site with a parser
A parser reads a site’s page and returns its data as JSON: Reddit posts, Google Maps places, Amazon products, YouTube videos and more. Send the page URL and the parser’s name:parsed calls scrape with the format { type: "json", parser }. The parser name is typed, so your editor lists every parser. await stophy.parsers() returns each parser with the page it reads and what it returns.
The third argument sends the parser’s options, such as the next page:
Crawl a site
crawl answers at once with an id. Ask crawl.status for the pages:
status is scraping until the crawl is completed. A status answer holds up to 100 finished pages. Wait until the status is completed. When the answer has a next link, send the cursor value from that link with the same id to get the rest. crawl.cancel({ id }) stops the crawl and keeps the pages already read. A crawl and its pages are kept for 24 hours.
batch.scrape takes a list of URLs and works the same way, with batch.scrape.status and batch.scrape.cancel.
Extract fields from pages
extract.result throws a StophyError with the code notFound until the result is ready. Results are kept for 24 hours.
Handle errors
StophyError has code, message, retryable, retryAfterSeconds, status, and requestId. The message says what went wrong and what to do next.
The SDK retries network errors and the HTTP statuses 429, 500, 502, 503, and 504, and it waits as long as the API asks. If the API asks for a wait longer than 60 seconds, the SDK throws right away with retryAfterSeconds set.
Options
Each method also takes
signal to cancel the request.
Check your account
limits returns your balance and rate limit. usage returns your all-time usage. logs returns your recent calls. All three need an API key.