Skip to content
scraper.tools

API reference

Everything the builder does goes through this API. Requests and responses are JSON. The base URL is https://scraper.tools.

Extract data from a page

Send a url and an extract description. The response has columns, rows, a per-page report in pages, and an outcome of complete, partial or failed.

To parse HTML you already have, send html (and optionally baseUrl) instead of url. No request is made to any site in that case.

This endpoint needs no key. It is limited to 40 page fetches per 5 minutes per address, or 200 with a key.

POST /api/v1/extract
curl -X POST https://scraper.tools/api/v1/extract \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://quotes.toscrape.com/",
    "extract": {
      "kind": "fields",
      "row": { "type": "css", "value": "div.quote" },
      "fields": [
        { "name": "text", "selector": "span.text" },
        { "name": "author", "selector": ".author" },
        { "name": "tags", "selector": "a.tag", "multiple": true },
        { "name": "about", "selector": ".//a[contains(@href, \"/author/\")]",
          "selectorType": "xpath", "extract": "attr", "attr": "href" }
      ]
    },
    "pagination": {
      "kind": "next-link",
      "selector": { "type": "css", "value": "li.next > a" },
      "maxPages": 3
    }
  }'

The extract object

kind: "fields"

One output row per element matched by row. Leave row out to get a single record for the page. Each field has:

  • name: the column name.
  • selector: evaluated inside each row. Empty means the row element itself.
  • selectorType: css (default) or xpath. Start a relative XPath with .//.
  • extract: text (default), html or attr with an attr name. URL attributes such as href and src are returned as absolute URLs.
  • multiple: return every match as a list instead of the first.

Other kinds

  • { "kind": "table", "index": 0 }: the nth HTML table, with header detection and merged cells expanded.
  • { "kind": "links" }: every URL on the page. Optional types (link, image, script, stylesheet, media, frame), sameHostOnly and contains.
  • { "kind": "structured" }: JSON-LD, Microdata and Open Graph. The full nested output is in data.

Pagination

  • next-link: a selector for the link to the next page and maxPages. The link must stay on the same host.
  • url-pattern: a template containing {page}, with from, to and optional step.

A run fetches at most 25 pages and returns at most 10,000 rows.

Authentication

Endpoints marked “Key” need an API key from Settings, sent as a bearer token. A key belongs to one workspace and can read and change everything in it.

Call the API from a server or a script. Browsers on other sites cannot call it, because cross-origin requests are not enabled.

Download a scraper's newest data
curl -H "Authorization: Bearer st_your_key" \
  "https://scraper.tools/api/v1/scrapers/scr_123/latest?format=csv" \
  -o latest.csv

Endpoints

RequestAuthWhat it does
POST/api/v1/extractNoneFetch a URL (or take HTML you send) and extract data. Nothing is stored.
POST/api/v1/fetchNoneFetch one page and return its HTML with a fetch report.
GET/api/v1/robots?url=…&agent=…NoneWhat robots.txt says about a URL for a user agent.
GET/api/v1/scrapersKeyList saved scrapers with their last run.
POST/api/v1/scrapersKeySave a scraper: name, config and optional scheduleMinutes.
GET/api/v1/scrapers/{id}KeyOne scraper.
PATCH/api/v1/scrapers/{id}KeyChange name, config or scheduleMinutes (null turns the schedule off).
DELETE/api/v1/scrapers/{id}KeyDelete a scraper and its results.
POST/api/v1/scrapers/{id}/runKeyRun now. Responds when the run has finished, with its rows.
GET/api/v1/scrapers/{id}/runsKeyRun history without row data.
GET/api/v1/scrapers/{id}/latestKeyNewest run that produced data. Add ?format=csv|xlsx|json to download.
GET/api/v1/runs/{id}KeyOne run with rows. Add ?format=csv|xlsx|json to download.
GET/api/v1/workspaceKeyWorkspace details, usage and limits.

Errors

Failures return a matching HTTP status and a body with a stable code and a readable message.

A multi-page run that fails part-way still answers 200: check outcome and error in the body, and use the rows that were collected.

Error body
{
  "error": {
    "code": "ROBOTS_DISALLOWED",
    "message": "example.com's robots.txt does not allow fetching this page."
  }
}
CodeStatusMeaning
INVALID_REQUEST400The body or a parameter is malformed. The message names the field.
INVALID_SELECTOR400A CSS selector or XPath expression could not be parsed.
INVALID_URL400Not an http(s) URL, or it contains credentials.
BLOCKED_HOST400The address is on a private or reserved network.
UNAUTHENTICATED401The endpoint needs an API key and none was sent.
INVALID_API_KEY401The key is wrong or was deleted.
ROBOTS_DISALLOWED403The site's robots.txt does not allow this URL.
ACCESS_RESTRICTED403The site answered 401, 403, 407 or 451, or showed a bot check.
UNSUPPORTED_CONTENT415The URL returned something other than HTML or text.
RATE_LIMITED429Too many API calls. See the Retry-After header.
RATE_LIMITED_BY_SITE429The target site answered 429.
HOST_BUSY429The target site is already being fetched at its polite rate.
ROBOTS_UNREACHABLE502robots.txt returned a server error or timed out, so the site is off limits for now.
HTTP_ERROR502The target site answered with another 4xx or 5xx status.
NETWORK502DNS, connection or TLS failure reaching the target site.
TIMEOUT504The target site did not respond in time.