# web.extract

Read named values from one public web page with your own CSS or XPath rules, and get them as one structured record.

Web page extraction rules, one of the Web scrapers.

| | |
| --- | --- |
| Id | `web.extract` |
| Version | 1 |
| Billed per | request — 1 unit for a charged run |
| Runs | within one request |

Start it with `POST /v1/scrapers/web.extract/runs`. How runs work is in [Running a scraper](https://docs.enrichednow.com/running-a-scraper.md); what a run costs is in [Usage and units](https://docs.enrichednow.com/usage-and-units.md).

## Inputs

The fields of `input`. A field that is not listed here is refused.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `url` | string | yes | The page's address: http or https, on a public host name. Limit: at most 2048 characters. |
| `rules` | object of string or object values | yes | What to read from the page: a name for each value, and the rule that selects it. A rule is a CSS selector or an XPath expression as a string (the text of the first match), or an object: `selector`, and optionally `type` (`css`, `xpath`), `attribute` (return an attribute, e.g. `href`), `output` (`text` or `html`), `multiple` (a list of every match) and `fields` (rules applied inside each match, giving an object). |
| `render` | boolean | no | False: the rules read the page as the server sent it. True: the page is loaded in a browser first and the rules read it after its JavaScript ran. Default: `false`. |
| `wait_for_selector` | string | no | With `render`: a CSS selector that must be in the page before it is read, e.g. `ul.results li`. Limit: at most 200 characters. |
| `wait_ms` | integer | no | With `render`: milliseconds to wait after the page loaded. Limit: 0 to 10000. Default: `0`. |
| `timeout_s` | number | no | Seconds for reading the page. Limit: 5 to 60. Default: `30`. |

## Record fields

Every record of a run has these fields. A value that is not known is `null` — never an empty string and never `0`.

| Field | Type | Notes |
| --- | --- | --- |
| `url` | string | The address that was asked for. |
| `final_url` | string | The address of the page that was read, after redirects. |
| `status` | integer | The HTTP status of the page. |
| `rendered` | boolean | True when the page was loaded in a browser before the rules read it. |
| `data` | object | One entry per rule, under the rule's name: a string, a list of strings, an object (a rule with `fields`) or a list of objects. Null, or an empty list, where the rule selected nothing. |
| `matched` | object of integer values | For each rule, how many elements its selector found in the page. |
| `truncated` | boolean | True when something was cut: the page was longer than 3000000 bytes, a list had more than 1000 matches, or a value was longer than 50000 characters. |
| `fetched_at` | string (date-time) | When the page was read, in UTC. |

## Example request

It starts a run with this scraper's example input and waits up to 60 seconds for it. The key is read from `ENRICHEDNOW_API_KEY`.

```bash
curl -X POST "https://api.enrichednow.com/v1/scrapers/web.extract/runs?wait=60" \
  -H "Authorization: Bearer $ENRICHEDNOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"input":{"url":"https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html","rules":{"title":"div.product_main h1","price":"p.price_color","details":{"selector":"table.table tr","multiple":true,"fields":{"name":"th","value":"td"}}}}}'
```

## Example response

The run, once it has ended. A run that has not ended within `wait` comes back with `202` and the status `queued` or `running`.

```json
{
  "id": "run_841742f37553189ff9c27ba1",
  "scraper_id": "web.extract",
  "scraper_version": 1,
  "status": "ok",
  "reason": null,
  "input": {
    "url": "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html",
    "rules": {
      "title": "div.product_main h1",
      "price": "p.price_color",
      "details": {
        "selector": "table.table tr",
        "multiple": true,
        "fields": {
          "name": "th",
          "value": "td"
        }
      }
    }
  },
  "record_count": 1,
  "units": 1,
  "units_per_request": 1,
  "units_per_record": null,
  "units_per_page": null,
  "diagnostics": {
    "requests": 1,
    "bytes": 259214,
    "wall_ms": 885,
    "facts": {}
  },
  "created_at": "2026-11-16T22:37:50.170950Z",
  "started_at": "2026-11-16T22:37:50.178331Z",
  "finished_at": "2026-11-16T22:37:51.066313Z"
}
```

Its records, from `GET /v1/runs/{id}/records`. The record is a real one: this scraper's own parser read it from a page recorded from the site.

```json
{
  "records": [
    {
      "url": "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html",
      "final_url": "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html",
      "status": 200,
      "rendered": false,
      "data": {
        "title": "A Light in the Attic",
        "price": "£51.77",
        "details": [
          {
            "name": "UPC",
            "value": "a897fe39b1053632"
          },
          {
            "name": "Product Type",
            "value": "Books"
          },
          {
            "name": "Price (excl. tax)",
            "value": "£51.77"
          }
        ]
      },
      "matched": {
        "title": 1,
        "price": 1,
        "details": 7
      },
      "truncated": false,
      "fetched_at": "2026-11-19T18:07:42.196395Z"
    }
  ],
  "next_cursor": null
}
```

What was done to the record for this page, and nothing else — the API returns every value whole. A text that was cut ends with `… [truncated]`.

- Shortened: `data.details`: 7 items, the first 3 shown.

A run does not always end `ok`. [Results and statuses](https://docs.enrichednow.com/results-and-statuses.md#reason-codes) lists every status and the reasons every scraper shares; [the reasons of the Web scrapers](https://docs.enrichednow.com/results-and-statuses.md#web) are in their own section there.
