Extract HTML Tables to JSON / CSV Online
Extract every table of a web page or HTML snippet to JSON or CSV, with merged cells (rowspan / colspan) expanded and multi-row headers combined.
Result
Press “Run” to see the result.
The HTML tables API turns <table> elements into data. Give it a URL or raw html and it returns each table with its caption, id, number of rows and columns, column headers and the rows as objects keyed by header (or as plain arrays with format=rows). Merged cells are expanded into a regular grid, so a cell with rowspan="2" appears in both rows, and multi-row headers are combined (“Price / Buy”, “Price / Sell”).
Headers are detected from <thead> and rows of <th>, or from a first row of labels (header=first or none to force). Nested layout tables are skipped by default, min_rows drops tiny tables and index selects one table; with format=csv that table comes back as a UTF-8 CSV file (with BOM, so Excel opens Vietnamese text correctly).
Pages are fetched with the same protections as the other web APIs (no private addresses, 5 MB limit). Tables rendered by JavaScript after the page loads are not visible to the API.
Use this in your code
curl -X POST "https://apibox.io.vn/v1/html-tables" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"html":"<table><thead><tr><th rowspan=\"2\">Tên</th><th colspan=\"2\">Giá</th></tr><tr><th>Mua</th><th>Bán</th></tr></thead><tr><td>USD</td><td>25,380</td><td>25,790</td></tr></table>"}'const res = await fetch('https://apibox.io.vn/v1/html-tables', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"html": "<table><thead><tr><th rowspan=\"2\">Tên</th><th colspan=\"2\">Giá</th></tr><tr><th>Mua</th><th>Bán</th></tr></thead><tr><td>USD</td><td>25,380</td><td>25,790</td></tr></table>"
}),
});
const data = await res.json();
console.log(data);import requests
res = requests.post(
"https://apibox.io.vn/v1/html-tables",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={"html": "<table><thead><tr><th rowspan=\"2\">Tên</th><th colspan=\"2\">Giá</th></tr><tr><th>Mua</th><th>Bán</th></tr></thead><tr><td>USD</td><td>25,380</td><td>25,790</td></tr></table>"},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/html-tables');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => '{"html":"<table><thead><tr><th rowspan=\\"2\\">Tên</th><th colspan=\\"2\\">Giá</th></tr><tr><th>Mua</th><th>Bán</th></tr></thead><tr><td>USD</td><td>25,380</td><td>25,790</td></tr></table>"}',
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));API documentation → Get a free API key
FAQ
How are merged cells handled?
Their value is copied into every cell they span, so every row has the same number of columns.
Can I get Excel-friendly CSV?
Yes, format=csv&index=N returns UTF-8 with a BOM and CRLF line endings, which Excel opens with Vietnamese characters intact.
Why is a table missing?
It is probably built by JavaScript in the browser; the API reads the HTML returned by the server.