Extract Data from a Web Page with CSS Selectors
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.
Result
Press “Run” to see the result.
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.
Use this in your code
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"}}}}'const res = await fetch('https://apibox.io.vn/v1/html-extract', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"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"
}
}
}
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/html-extract",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"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"}}}},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/html-extract');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"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"}}}}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));API documentation → Get a free API key
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.