# HTML Table to JSON/CSV Extractor (`andok/html-table-extractor`) Actor

Convert complex web tables into clean, structured JSON or CSV data. Automate data entry and reporting without writing custom parsers.

- **URL**: https://apify.com/andok/html-table-extractor.md
- **Developed by:** [Andok](https://apify.com/andok) (community)
- **Categories:** Business, Developer tools
- **Features:** Limited permissions
- **Stats:** 16 total users, 2 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.47 / 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.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

Pull structured table data from any web page and export it as clean JSON or CSV. No custom scraper needed — just provide URLs containing HTML tables and get rows and columns as structured data. Process multiple pages in a single run.

### Features

- **Automatic table detection** — finds all `<table>` elements on each page
- **Header recognition** — detects `<th>` headers or uses the first row as column names
- **Bulk processing** — extract tables from multiple URLs in one run
- **Clean JSON output** — each table row becomes a structured object with named fields
- **Configurable concurrency** — process 1 to 50 URLs in parallel

### Input

| Field | Type | Required | Default | Description |
|-------|------|----------|---------|-------------|
| `urls` | `array` | No | — | List of webpage URLs to extract tables from |
| `url` | `string` | No | — | Single URL for backwards compatibility (use `urls` for bulk) |
| `timeoutSeconds` | `integer` | No | `15` | Maximum seconds to wait for each URL response |
| `concurrency` | `integer` | No | `10` | Number of URLs to process in parallel (1-50) |

#### Input Example

```json
{
  "urls": [
    "https://en.wikipedia.org/wiki/List_of_countries_by_population_(United_Nations)"
  ]
}
```

### Output

Each URL produces one dataset item containing all tables found on the page.

Key output fields:

- `inputUrl` (`string`) — the original URL provided
- `finalUrl` (`string`) — the URL after following redirects
- `status` (`number`) — HTTP status code
- `tableCount` (`number`) — number of tables found on the page
- `tables` (`array`) — array of table objects, each containing headers and rows
- `error` (`string`) — error message if extraction failed, otherwise `null`
- `checkedAt` (`string`) — ISO 8601 timestamp

#### Output Example

```json
{
  "inputUrl": "https://en.wikipedia.org/wiki/List_of_countries_by_population_(United_Nations)",
  "finalUrl": "https://en.wikipedia.org/wiki/List_of_countries_by_population_(United_Nations)",
  "status": 200,
  "tableCount": 2,
  "tables": [
    {
      "headers": ["Rank", "Country", "Population"],
      "rows": [
        ["1", "India", "1,450,935,791"],
        ["2", "China", "1,419,321,278"]
      ]
    }
  ],
  "error": null,
  "checkedAt": "2025-01-15T10:30:00.000Z"
}
```

### Pricing

| Event | Cost |
|-------|------|
| Table Extracted | Pay-per-event (see actor pricing page) |

### Use Cases

- **Data collection** — grab financial data, sports stats, or product specs from web pages without writing a scraper
- **Spreadsheet import** — convert HTML tables to CSV or JSON for import into Excel or Google Sheets
- **Research automation** — extract tabular data from Wikipedia, government sites, or academic pages
- **Price monitoring** — pull pricing tables from competitor websites

### Related Actors

| Actor | What it adds |
|-------|-------------|
| [Web Page to Markdown Converter for LLMs](https://apify.com/andok/markdown-extractor) | Convert full page content to Markdown including tables |
| [JSON-LD Schema Extractor](https://apify.com/andok/jsonld-extractor) | Extract structured data from Schema.org markup |

# Actor input Schema

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

List of webpage URLs to extract HTML tables from. All <table> elements on each page will be detected and parsed.

## `url` (type: `string`):

Single URL to extract tables from. For backwards compatibility — use the URLs field above for bulk processing.

## `timeoutSeconds` (type: `integer`):

Maximum seconds to wait for each URL response before timing out. Increase for slow-loading pages.

## `concurrency` (type: `integer`):

Number of URLs to process in parallel. Lower this if you experience rate limiting from target sites.

## Actor input object example

```json
{
  "urls": [
    "https://en.wikipedia.org/wiki/List_of_countries_by_population_(United_Nations)"
  ],
  "timeoutSeconds": 15,
  "concurrency": 10
}
```

# Actor output Schema

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

No description

## `resultsCsv` (type: `string`):

No description

## `run` (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": [
        "https://en.wikipedia.org/wiki/List_of_countries_by_population_(United_Nations)"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("andok/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": ["https://en.wikipedia.org/wiki/List_of_countries_by_population_(United_Nations)"] }

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

```

## MCP server setup

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