# Extract data with CSS selectors

Works on the saved HTML, so the crawl needs `include_html`. Repeat with `next_offset` until it is null.

`POST https://api.seoscraper.io/v1/crawls/{crawl_id}/extract`

## Path parameters

- `crawl_id` string: Crawl identifier.

## Request body

- `fields` object[]: What to extract from each page.
  - `name` string: Name of the field in the result.
  - `selector` string: CSS selector.
  - `format` string? (text, markdown, html, clean_html, attribute): clean_html: no attributes, styles and scripts. attribute: value of the attribute in `attribute`.
  - `attribute` string | null?: Attribute name, required when format is attribute.
- `page_ids` integer[] | null?: Only these pages. Without it, pages matching the filters.
- `q` string?: Text in the URL or title. With `*` it is a path pattern, e.g. `/blog/*`.
- `filters` string[]?: Conditions written as `field:operator:value`, e.g. `path:pattern:/blog/*` or `words:gte:300`.
- `match` string? (all, any): Should a page meet all filters or any of them.
- `limit` integer?: Number of pages to return.
- `offset` integer?: Number of pages to skip.

## Response 200

- `total` integer: Number of selected pages.
- `next_offset` integer | null: Offset of the next request. null at the end.
- `pages` object[]: May be shorter than `limit` when the pages are large.
  - `id` integer: Page number in the crawl.
  - `url` string: Address of the page.
  - `title` string: Content of the title tag.
  - `status` integer | null: null when the page could not be fetched.
  - `has_html` boolean: false: the HTML of this page was not saved.
  - `truncated` boolean: true: the page had more data than the limit allows.
  - `values` object: Field name and all its matches, in page order.

## Errors

- 401: unauthorized
- 404: not_found
- 409: crawl_not_ready
- 422: invalid_request, invalid_filter, invalid_selector

## Example

```bash
curl -X POST "https://api.seoscraper.io/v1/crawls/CRAWL_ID/extract" \
  -H "Authorization: Bearer ssk_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"fields":[{"name":"title","selector":"h1"},{"name":"price","selector":".price_color"}],"filters":["path:pattern:/catalogue/*"],"limit":1}'
```

```json
{
  "total": 49,
  "next_offset": 1,
  "pages": [
    {
      "id": 4,
      "url": "https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html",
      "title": "A Light in the Attic | Books to Scrape - Sandbox",
      "status": 200,
      "has_html": true,
      "truncated": false,
      "values": {
        "title": [
          "A Light in the Attic"
        ],
        "price": [
          "£51.77"
        ]
      }
    }
  ]
}
```
