Developers

Web Scraping API

Reference

Custom Parser

Extract named fields from a generic page using selector and transformation rules.

Define your output fields

Set parse: true and provide a parsing_instructions object. Each field name becomes a key in parsed content. Its _fns sequence selects or transforms the value.

Extract a title and links
{
  "source": "universal",
  "url": "https://example.com/",
  "parse": true,
  "parsing_instructions": {
    "title": {
      "_fns": [
        {
          "_fn": "xpath_one",
          "_args": [
            "//h1/text()",
            "//title/text()"
          ]
        }
      ]
    },
    "links": {
      "_fns": [
        {
          "_fn": "xpath",
          "_args": [
            "//a/@href"
          ]
        }
      ]
    }
  }
}

CSS and XPath selectors

xpath and css can return multiple matches. xpath_one and css_one select the first match. CSS returns HTML elements; add element_text to extract their text. XPath expressions can select text or attributes directly.

Fallbacks and missing values

Selector arguments are arrays. Multiple expressions are fallbacks, so the next expression is tried when the preceding one matches nothing. Validate required fields in your application and inspect parser status instead of assuming an empty field is valid.

Parser reference

Search documentation

Search guides, products and reference pages.