HTML Tables to JSON API
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.
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.
Parameters
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
url | body|query | string | no | Page URL (or send html). | |
html | body | string | no | Raw HTML. | |
index | body|query | number | no | Only this table (0-based). | |
format | body|query | string | no | json | json, rows or csv (with index). |
header | body|query | string | no | auto | auto, first or none. |
min_rows | body|query | number | no | 1 | Skip tables with fewer data rows. |
Example
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));Response
{
"source": null,
"table_count": 1,
"returned": 1,
"tables": [
{
"index": 0,
"caption": null,
"id": null,
"rows": 1,
"columns": 3,
"headers": [
"Tên",
"Giá / Mua",
"Giá / Bán"
],
"data": [
{
"Tên": "USD",
"Giá / Mua": "25,380",
"Giá / Bán": "25,790"
}
]
}
]
}
Use cases
- Scrape price lists, exchange rates and statistics tables
- Import tables from Wikipedia into spreadsheets
- Convert HTML reports to CSV for accounting
- Monitor tables on supplier websites
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.
Related APIs
HTML to Markdown
Convert HTML or any web page URL into clean GitHub-flavored Markdown, with tables, optional article extraction and absolute links.
</>Markdown to HTML
Render GitHub-flavored Markdown to HTML with tables and strikethrough. Output is sanitized by default to strip scripts and event handlers.
<✓>HTML Sanitizer
Strip scripts, iframes, forms, event handlers, inline styles and javascript: links from untrusted HTML before you display it.