# HTML data extractor API

> Extract data from a web page or raw HTML with CSS selectors into JSON — lists, attributes, number / date filters, pagination — or turn a page into RSS.

- Endpoint: `GET | POST https://apibox.io.vn/v1/html-extract`
- Category: Web & SEO
- HTML docs: https://apibox.io.vn/docs/html-extract/ (Vietnamese: https://apibox.io.vn/vi/docs/html-extract/)
- Online tool: https://apibox.io.vn/tools/html-extract/
- Authentication: `Authorization: Bearer <API key>` or `X-API-Key: <API key>` (free key: https://apibox.io.vn/dashboard/#signup)

Send a public `url` (or `html`) and a `fields` map. A value is a CSS selector with an optional attribute and filters: `"h1"`, `"a.more@href"` (links and image sources become absolute URLs), `".price | number"`. A name ending in `[]` returns every match; an object `{"selector": ".product", "fields": {...}}` returns a list of records, with selectors relative to each item. Filters: trim, lower, upper, oneline, number (150.000 ₫ → 150000), int, date (dd/mm/yyyy → ISO), url, remove_accents, `regex:…` (first group), `replace:a=>b`, `split:,`, `default:…`.

`next` (a selector for the "next page" link) with `max_pages` (up to 3 on Free, 5 on paid plans) follows pagination on the same site and concatenates the lists. `format=rss` or `json_feed` turns a page without a feed into one: `feed` = `{"item": "article", "title": "h2", "link": "a@href", "date": "time@datetime", "summary": "p", "image": "img@src"}`.

Fair use: pages are fetched with our bot identity (APIBoxBot), robots.txt is respected (disallowed paths are refused), JavaScript is not executed, no cookies or logins, and sites whose terms forbid automated extraction or that sit behind captchas (search engines, social networks, large marketplaces, tax / business-registry portals, gold / fuel price and power-outage pages) are blocked. Pages up to 2 MB.

## Parameters

| Name | In | Type | Required | Default | Description |
|---|---|---|---|---|---|
| `url` | body|query | string | no |  | Public page to fetch (or send `html`). |
| `html` | body | string | no |  | Raw HTML instead of a URL (with optional `base_url`). |
| `fields` | body|query | object | yes |  | Map of name → `selector[@attr] \| filter` or `{selector, fields}`. |
| `next` | body|query | string | no |  | Selector of the next-page link (pagination). |
| `max_pages` | body|query | number | no | `1` | Pages to follow with `next` (Free 3, paid 5). |
| `format` | body|query | string | no | `json` | `json`, `rss` or `json_feed`. |
| `feed` | body|query | object | no |  | Feed mode selectors: item, title, link, date, summary, image, author. |
| `limit` | body|query | number | no | `500` | Maximum matches per list (1-2,000). |

## Example request

```bash
curl -X POST "https://apibox.io.vn/v1/html-extract" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"html":"<h1>Cửa hàng</h1><div class=\"sp\"><a href=\"/p/1\">Áo thun</a><span class=\"gia\">150.000 ₫</span></div><div class=\"sp\"><a href=\"/p/2\">Quần jean</a><span class=\"gia\">1.250.000 ₫</span></div>","base_url":"https://shop.example.vn/","fields":{"tieu_de":"h1","san_pham":{"selector":".sp","fields":{"ten":"a","url":"a@href","gia":".gia | number"}}}}'
```

## Example response

```json
{
  "url": null,
  "title": null,
  "pages": 1,
  "counts": {
    "san_pham": 2
  },
  "data": {
    "tieu_de": "Cửa hàng",
    "san_pham": [
      {
        "ten": "Áo thun",
        "url": "https://shop.example.vn/p/1",
        "gia": 150000
      },
      {
        "ten": "Quần jean",
        "url": "https://shop.example.vn/p/2",
        "gia": 1250000
      }
    ]
  }
}
```

## Use cases

- Pull product names and prices from your own shop pages into a sheet
- Make an RSS feed for a news or notice page that has none
- Collect event, job or tender listings from public pages for n8n / Make
- Parse HTML you already downloaded with the same selector rules

## FAQ

### Why is a site refused?

Either its robots.txt disallows our bot on that path, or it is on our list of sites that forbid automated extraction or use captchas / logins. We do not bypass either.

### Does it run JavaScript?

No. Content that a page loads with JavaScript after it opens is not visible; look for the site’s API or feed instead.

### How is this different from page-watch?

html-extract returns structured data on each call; page-watch stores a snapshot and alerts you when it changes.
