# HTML Table Extractor: tables to rows, CSV and JSON (`examsens.ai/html-table-extractor`) Actor

Extracts every HTML table from the pages you list into rows keyed by column header, lining up colspan and rowspan cells and joining stacked headers, and saves each table as a CSV file and a JSON file.

- **URL**: https://apify.com/examsens.ai/html-table-extractor.md
- **Developed by:** [Ed Rayyis](https://apify.com/examsens.ai) (community)
- **Categories:** Developer tools, Automation
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.40 / 1,000 table extracteds

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 Table Extractor: tables to rows, CSV and JSON

Give it a list of page URLs, or paste HTML, and it returns every table on each page as rows keyed by column name. Each table is also saved as a CSV file and a JSON file you can download straight away.

### What it handles

- colspan and rowspan. Every table is laid out on a full grid. A merged cell fills each position it covers, so values stay in the right column and a cell that spans two rows appears in both.
- Stacked headers. When a header has two or more rows, the names are joined per column: a "Revenue" cell over "USD" and "EUR" gives the columns `Revenue / USD` and `Revenue / EUR`. Repeated names get a number, such as `Total_2`.
- Header detection. It uses the `thead` rows, or the leading rows made only of `th` cells. You can force the first row as the header, or use no header at all.
- Footnote marks. Superscript marks such as `[1]` or `[a]` are removed from cell text by default.
- Line breaks and nested tables. A line break inside a cell becomes a space. A table inside a cell is returned as its own table, and the outer cell keeps its own text.
- Context. Each table comes with its caption and the nearest heading above it.
- Filters. Skip tables below a minimum number of data rows or columns (2 and 2 by default), keep only tables whose caption, heading or column names contain a word, and cap the tables per page. Tables marked `role="presentation"` are skipped.
- Numbers. Optionally, cells holding only a number (such as `1,200` or `35.5`) become numbers in the JSON rows.

### Input

- Page URLs, pasted HTML, or both
- Header rows: detect (default), first row, or none
- Minimum data rows (default 2) and minimum columns (default 2)
- Only tables mentioning (optional text)
- Maximum tables per page (default 50)
- Remove footnote marks (default on), turn number cells into numbers (default off)
- One dataset item per row (default off), include Markdown (default off)
- Pages at once (default 5) and page timeout (default 30 seconds)

### Output

**Dataset:** one item per table with `url`, `tableIndex` (its position among the tables on the page), `caption`, `heading`, `columns`, `rowCount`, `columnCount`, `headerRowCount`, `rows` (one object per row, keyed by column name), and `csvUrl` and `jsonUrl` links to the files. With "One dataset item per row" on, each row is its own item with `rowIndex` and `row`, which exports cleanly to CSV or Excel.

**Key value store:** for every table, `table-<page>-<table>.csv` (header row first, the text as shown on the page) and `table-<page>-<table>.json` (the same fields as the dataset item). Pasted HTML is page 0000.

A page that cannot be read, or has no table that meets the filters, returns an item with `ok: false` and the reason, such as `HTTP 404` or `no tables on the page`. The rest of the run carries on.

### Pricing

Pay per event: one event per table extracted. Pages with no tables and pages that fail are not charged. The run stops when it reaches the maximum charge you set.

### Scope and conduct

Only the HTML of each URL you list is downloaded. Tables built by scripts after the page loads are not seen. Links are not followed. No login is used.

### Support

Questions and problems: the Issues tab on this page. Replies are written by an AI assistant on behalf of the developer and reviewed by the developer.

# Actor input Schema

## `urls` (type: `array`):

Pages with tables. Each URL is fetched once; links are not followed.

## `html` (type: `string`):

Paste HTML that holds tables. It is read as one more input, next to any URLs.

## `headerMode` (type: `string`):

Detect uses the thead rows, or the leading rows made only of th cells. First row always uses the first row. None names the columns column_1, column_2 and so on, and keeps every row as data.

## `minRows` (type: `integer`):

Skip tables with fewer data rows than this. Helps leave out layout tables.

## `minColumns` (type: `integer`):

Skip tables with fewer columns than this.

## `tableTextFilter` (type: `string`):

Keep only tables whose caption, nearest heading above, or column names contain this text (not case sensitive). Leave empty to keep all.

## `maxTablesPerPage` (type: `integer`):

Stop after this many tables on each page. Each table output is one billable event.

## `removeFootnoteMarks` (type: `boolean`):

Drop superscript reference marks such as \[1] or \[a] from cell text.

## `parseNumbers` (type: `boolean`):

In the JSON rows, a cell holding only a number such as 1,200 or 35.5 becomes a number. Other cells stay text. The CSV file keeps the text as shown on the page.

## `oneItemPerRow` (type: `boolean`):

Write each table row as its own dataset item, ready for a spreadsheet export. Off writes one item per table with all its rows.

## `includeMarkdown` (type: `boolean`):

Add a Markdown version of each table to its dataset item.

## `maxConcurrency` (type: `integer`):

How many pages to fetch in parallel.

## `timeoutSecs` (type: `integer`):

Give up on a page after this many seconds.

## Actor input object example

```json
{
  "urls": [
    {
      "url": "https://en.wikipedia.org/wiki/List_of_largest_companies_by_revenue"
    }
  ],
  "headerMode": "auto",
  "minRows": 2,
  "minColumns": 2,
  "maxTablesPerPage": 50,
  "removeFootnoteMarks": true,
  "parseNumbers": false,
  "oneItemPerRow": false,
  "includeMarkdown": false,
  "maxConcurrency": 5,
  "timeoutSecs": 30
}
```

# Actor output Schema

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

No description

## `files` (type: `string`):

No description

# 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 = {
    "urls": [
        {
            "url": "https://en.wikipedia.org/wiki/List_of_largest_companies_by_revenue"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("examsens.ai/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 = { "urls": [{ "url": "https://en.wikipedia.org/wiki/List_of_largest_companies_by_revenue" }] }

# Run the Actor and wait for it to finish
run = client.actor("examsens.ai/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 '{
  "urls": [
    {
      "url": "https://en.wikipedia.org/wiki/List_of_largest_companies_by_revenue"
    }
  ]
}' |
apify call examsens.ai/html-table-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,examsens.ai/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/ORf9dFuyQjcj1d31a/builds/n43kbbG5kRJIRKhdM/openapi.json
