All examples
advanced
Scrape a page's tables
Extract HTML tables from a page as JSON.
Point TabularJS at an HTML string and get every <table> on the page as a worksheet, perfect for quick scraping tasks. The first row of each table becomes its column titles.
js
import tabularjs from 'tabularjs';
const html = await fetch('https://example.com/prices').then(r => r.text());
const result = await tabularjs(html);
// One worksheet per <table>: Table1, Table2...
for (const sheet of result.worksheets) {
console.log(sheet.worksheetName, sheet.columns.map(c => c.title), sheet.data);
}
// Or only one of them
const second = await tabularjs(html, { tableIndex: 1 });Live Preview
Sample output for a file with employee data.
stdout
{
"worksheets": [
{
"name": "Sheet1",
"data": [
["Name", "Department", "Salary", "Start Date"],
["Alice Johnson", "Engineering", 95000, "2021-03-15"],
["Bob Smith", "Marketing", 72000, "2022-01-10"],
["Carol Williams", "Engineering", 88000, "2020-07-22"],
["David Brown", "Design", 68000, "2023-02-08"],
["Eve Davis", "Engineering", 102000, "2019-11-30"]
]
}
]
}