# HTML Table Extractor - Web Page Tables to CSV, JSON & Excel (`wood-between-studio/html-table-extractor`) Actor

Extract every HTML table from web pages into clean JSON rows and CSV downloads: real headers, colspan and rowspan handled, numbers cleaned, links kept, CSS selector and keyword filter. Respects robots.txt. $1 per 1,000 tables.

- **URL**: https://apify.com/wood-between-studio/html-table-extractor.md
- **Developed by:** [Wood Between Studio](https://apify.com/wood-between-studio) (community)
- **Categories:** Developer tools, Automation, Integrations
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$1.00 / 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: Turn Web Page Tables into JSON, CSV and Excel

**Extract every HTML `<table>` from a list of web pages into clean, structured data.** Real header rows are detected (including multi-row headers), `colspan` and `rowspan` are expanded so columns line up, footnote markers are removed, numbers can be converted, links can be kept, and each table is also saved as a **CSV file with a download link**.

### Why use it?

- **Tables that actually line up.** Merged cells (`colspan`/`rowspan`) are filled in correctly, duplicate header names are made unique, repeated header rows are skipped.
- **Pick the right table.** CSS selector (e.g. `table.wikitable`), "contains text" keyword filter, minimum row count to skip layout tables; navigation boxes are ignored by default.
- **Two output shapes.** One item per table (with its rows inside) or one item per row, ready for CSV/Excel export.
- **Polite.** Respects each site's robots.txt and fetches every page once.
- **Cheap and fair.** **$1 per 1,000 tables**, no start fee. Pages without matching tables are free.

### Use cases

- Pulling statistics, rankings and reference lists (e.g. Wikipedia tables) into spreadsheets
- Price, spec and comparison tables on product and documentation pages you are allowed to reuse
- Turning public reports and government data pages into CSV
- Feeding tabular web data into Google Sheets, databases or LLM pipelines

### Input

| Field | Default | Notes |
|---|---|---|
| `startUrls` | (required) | Pages with tables |
| `tableSelector` | `table` | CSS selector |
| `containsText` | | Keep only tables containing this text |
| `minRows` | `2` | Minimum data rows |
| `outputMode` | `tables` | `tables` or `rows` |
| `cleanNumbers` | `false` | "1,234.5" / "45%" to numbers |
| `includeLinks` | `false` | Adds `<column>_link` fields |
| `saveCsv` | `true` | CSV per table in the key-value store |
| `maxTablesPerPage` | `50` | |

```json
{ "startUrls": ["https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population"], "tableSelector": "table.wikitable", "cleanNumbers": true }
```

### Output (tables mode)

```json
{
  "pageUrl": "https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population", "tableIndex": 0,
  "caption": "List of countries and territories by total population", "headers": ["Location", "Population", "% of world", "Date", "Source (official or from the United Nations)", "Notes"],
  "rowCount": 240, "columnCount": 6, "csvUrl": "https://api.apify.com/v2/key-value-stores/.../records/en.wikipedia.org-0-0", "status": "success",
  "rows": [{ "Location": "World", "Population": 8232000000, "% of world": 100, "Date": "13 Jun 2025", "Source (official or from the United Nations)": "UN projection", "Notes": "" }]
}
```

### Pricing

Pay per event: **$0.001 per table extracted** ($1 per 1,000). No start fee.

### Notes

Works on static HTML (tables built by JavaScript after page load are not seen). Only use it on pages whose terms allow reuse of their data, and respect copyright and licences (e.g. Wikipedia's CC BY-SA). Built by Wood Between Studio. Questions? Open an issue on the Issues tab.

# Actor input Schema

## `startUrls` (type: `array`):

Web pages that contain HTML <table> elements.

## `tableSelector` (type: `string`):

e.g. table.wikitable or #prices table.

## `containsText` (type: `string`):

Optional keyword; keeps only tables whose text includes it (case-insensitive).

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

Skip layout tables with fewer data rows.

## `outputMode` (type: `string`):

Rows mode is handy for export straight to CSV/Excel.

## `cleanNumbers` (type: `boolean`):

Turn "1,234.5" or "45%" cells into numbers.

## `includeLinks` (type: `boolean`):

Add a <column>\_link field for cells that contain a link.

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

Store a CSV file per table in the key-value store, with a download link.

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

Safety limit.

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

Pages fetched in parallel.

## Actor input object example

```json
{
  "startUrls": [
    "https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population"
  ],
  "tableSelector": "table",
  "minRows": 2,
  "outputMode": "tables",
  "cleanNumbers": false,
  "includeLinks": false,
  "saveCsv": true,
  "maxTablesPerPage": 50,
  "maxConcurrency": 5
}
```

# Actor output Schema

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

No description

## `summary` (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 = {
    "startUrls": [
        "https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("wood-between-studio/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 = { "startUrls": ["https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population"] }

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

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,wood-between-studio/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/bTKpdtYIqjmpJAGm9/builds/ydyK3ov2wtlpdf312/openapi.json
