# Wyciągnij dane selektorami CSS

Działa na zapisanym HTML-u, więc crawl musi mieć `include_html`. Powtarzaj zapytanie z `next_offset`, aż będzie null.

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

## Parametry ścieżki

- `crawl_id` string: Identyfikator crawla.

## Treść zapytania

- `fields` object[]: Co wyciągnąć z każdej strony.
  - `name` string: Nazwa pola w wyniku.
  - `selector` string: Selektor CSS.
  - `format` string? (text, markdown, html, clean_html, attribute): clean_html: bez atrybutów, stylów i skryptów. attribute: wartość atrybutu podanego w `attribute`.
  - `attribute` string | null?: Nazwa atrybutu, wymagana, gdy format to attribute.
- `page_ids` integer[] | null?: Tylko te strony. Bez tego pola strony pasujące do filtrów.
- `q` string?: Tekst w adresie albo tytule. Z `*` to wzorzec ścieżki, np. `/blog/*`.
- `filters` string[]?: Warunki w postaci `pole:operator:wartość`, np. `path:pattern:/blog/*` albo `words:gte:300`.
- `match` string? (all, any): Czy strona ma spełniać wszystkie warunki, czy dowolny z nich.
- `limit` integer?: Ile stron zwrócić.
- `offset` integer?: Ile stron pominąć.

## Odpowiedź 200

- `total` integer: Liczba wybranych stron.
- `next_offset` integer | null: Wartość offset następnego zapytania. Na końcu null.
- `pages` object[]: Może być krótsza niż `limit`, gdy strony są duże.
  - `id` integer: Numer strony w crawlu.
  - `url` string: Adres strony.
  - `title` string: Treść znacznika title.
  - `status` integer | null: null, gdy strony nie udało się pobrać.
  - `has_html` boolean: false: HTML tej strony nie został zapisany.
  - `truncated` boolean: true: strona miała więcej danych, niż pozwala limit.
  - `values` object: Nazwa pola i wszystkie dopasowania w kolejności na stronie.

## Błędy

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

## Przykład

```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"
        ]
      }
    }
  ]
}
```
