# HTML Tables to JSON & CSV (`springlike_meadowland/html-table-extractor`) Actor

Extract public HTML tables into structured JSON rows and optional per-table CSV files, with captions, headers, spans, source links and clear limits.

- **URL**: https://apify.com/springlike\_meadowland/html-table-extractor.md
- **Developed by:** [Akshay Aggarwal](https://apify.com/springlike_meadowland) (community)
- **Categories:** Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 saved tables

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## HTML Tables to JSON & CSV

Turn published HTML tables into structured rows for analysis, spreadsheets and automation. Give the Actor public page URLs; it returns one dataset item per table with its caption, column headers, expanded rows and source link. Save a separate CSV file for each table when you need one.

### Quick start

```json
{
  "pageUrls": ["https://www.w3.org/WAI/tutorials/tables/one-header/"],
  "maxTables": 1,
  "saveCsv": true
}
```

The example page has a table of event dates and venues. Its dataset item begins:

```json
{
  "source_url": "https://www.w3.org/WAI/tutorials/tables/one-header/",
  "table_index": 0,
  "caption": "",
  "headers": ["Date", "Event", "Venue"],
  "rows": [
    ["12 February", "Waltz with Strauss", "Main Hall"],
    ["24 March", "The Obelisks", "West Wing"],
    ["14 April", "The What", "Main Hall"]
  ],
  "row_count": 3,
  "column_count": 3,
  "truncated": false,
  "csv_key": "CSV_001_0000"
}
```

When `saveCsv` is true, open the `csv_key` record in the run's key-value store to download that table's CSV. When false, `csv_key` is omitted and no separate CSV files are created. The dataset is always JSON and has one item per saved table.

### Inputs and limits

| Input | Use |
| --- | --- |
| `pageUrls` | 1–20 public HTTPS pages with HTML `<table>` elements. |
| `tableIndexes` | Optional zero-based table indexes to select on each page. Leave out or use `[]` for all nonempty tables. Nested tables have their own indexes. |
| `maxTables` | Maximum saved tables across all pages, default 10, maximum 1,000. |
| `maxRowsPerTable` | Maximum expanded rows per table including header rows, default 100, maximum 1,000. |
| `maxCells` | Maximum expanded cells per table, including rectangular padding, default 5,000, maximum 20,000. |
| `saveCsv` | Write a separate CSV record per saved table, default false. |

The Actor reads public HTML returned by the page request. It does not sign in, render JavaScript, submit forms, or read tables inside PDFs or images. It follows public HTTPS redirects, accepts HTML responses up to 3 MiB, and caps each cell at 2,000 characters and total cell text at 500,000 characters per table. A source may also block automated requests. Check the run summary for errors and tables that reached limits.

Column headers come from `<thead>` or leading rows of `<th>` cells. Multirow headers are joined with `|`. Rowspan and colspan values are expanded into repeated cell values so every returned row has a consistent width. Row header cells within data rows remain in `rows`. Nested tables are separate items; their text is excluded from the parent cell. Empty tables are skipped. The Actor preserves table order and page order.

### Results and billing

Each saved dataset item is one table, regardless of its cell or row count. For pay-per-result pricing, one saved table is one billable result; check the current price in Apify Console. The Actor stops collecting when its run charge limit is reached and reports unprocessed pages in `OUTPUT`. A table shortened by a row, cell or text limit has `truncated: true` and may still be saved. The summary in the run's `OUTPUT` key reports fetched pages, saved and skipped tables, page errors and limit reasons. Errors and summary records are never added to the table dataset.

Use `row_count`, `column_count`, `truncated`, and the run summary to judge whether a table covers what you need. HTML tables used only for page layout can appear too; use `tableIndexes` to select the ones you want.

# Actor input Schema

## `pageUrls` (type: `array`):

Paste 1–20 public HTTPS pages containing HTML table elements. Pages that require login or JavaScript rendering are outside this Actor's scope.

## `tableIndexes` (type: `array`):

Zero-based indexes of tables to extract from each page. Leave empty to include all nonempty tables.

## `maxTables` (type: `integer`):

Stop after saving this many nonempty tables across all input pages.

## `maxRowsPerTable` (type: `integer`):

Includes header rows before they are moved into headers. Tables beyond this limit are marked truncated.

## `maxCells` (type: `integer`):

Counts cells after row and column spans are expanded, including padding to rectangular rows. Total cell text is capped at 500,000 characters per table.

## `saveCsv` (type: `boolean`):

CSV files go into the run's key-value store and add a csv\_key to each dataset row.

## Actor input object example

```json
{
  "pageUrls": [
    "https://www.w3.org/WAI/tutorials/tables/one-header/"
  ],
  "maxTables": 10,
  "maxRowsPerTable": 100,
  "maxCells": 5000,
  "saveCsv": false
}
```

# Actor output Schema

## `results` (type: `string`):

One dataset item per nonempty HTML table, with headers and a two-dimensional row array.

## `summary` (type: `string`):

Fetched and saved counts, limits, skipped tables and page errors.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "pageUrls": [
        "https://www.w3.org/WAI/tutorials/tables/one-header/"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("springlike_meadowland/html-table-extractor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "pageUrls": ["https://www.w3.org/WAI/tutorials/tables/one-header/"] }

# Run the Actor and wait for it to finish
run = client.actor("springlike_meadowland/html-table-extractor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "pageUrls": [
    "https://www.w3.org/WAI/tutorials/tables/one-header/"
  ]
}' |
apify call springlike_meadowland/html-table-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,springlike_meadowland/html-table-extractor"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/YD6f898NgOwo1Aft2/builds/RZegAup7ZlGqRrnu9/openapi.json
