HTML TABLES · ROWSPAN & COLSPAN

Complex HTML Table Extractor API: Rowspan, Colspan & Multi-Level Headers to Typed JSON

Target Query: html table rowspan colspan to json api · Category: Extraction Modality · Verified Rate: $0.015/hit ($0 on miss) · Updated: 2026-12-02

Direct Answer: Naive BeautifulSoup or regex table scrapers shift columns horizontally the moment a table contains `rowspan`, `colspan`, or two-tier `<thead>` group headers, silently corrupting pricing schedules and regulatory filings. Scrape-Anything runs a deterministic `HTMLParser` 2D cell-occupancy grid that expands every `rowspan` and `colspan`, flattens multi-level headers into unambiguous column keys, separates `<tfoot>` summary rows, normalizes numbers and currencies, and validates every row against your JSON Schema.

Engineering Mechanics & Deterministic Guardrails

HTML Table Edge Cases Handled by `html_tables.py`

HTML Table PatternWhy Naive Scrapers BreakScrape-Anything Grid ResolutionSchema Safety
`colspan="2"` header groupsHeader count != data cell count; columns driftExpands parent header across spanned columns and joins child headerStable column names across rows
`rowspan="3"` category labelsRows 2 and 3 shift left by 1 columnOccupies `(r+1, c)` and `(r+2, c)` and carries group value cleanlyZero column misalignment
`<tfoot>` totals rowMixed into line items, double-counting sumsSeparated into explicit `footer_rows` metadataClean aggregate math
Formatted currencies (`$1,499.00`)Stored as dirty strings breaking numeric schemasNumeric/currency parser extracts typed float & currency codePasses `type: number` validation
`rel="next"` table paginationTruncated after page 1Extracts `pagination.next_url` & page links automaticallyReady for `/v1/batch` traversal
Pure-Stream Multi-Format Latency vs Headless Browser Stacks (Relative Overhead) Headless Chrome Pool + Residential Proxy 3,200-8,500 ms LLM Markdown-to-JSON Two-Pass Pipeline 1,800-4,500 ms Scrape-Anything PDF FlateDecode Stream 15-120 ms Scrape-Anything Complex HTML Table Grid 10-90 ms Scrape-Anything __NEXT_DATA__ / JSON-LD 8-60 ms Scrape-Anything Binary .xlsx / CSV Gate 5-50 ms SQLite WAL Verified Archive Cache Hit < 5 ms

Normalized Multi-Row Table JSON Schema

{
  "type": "object",
  "required": [
    "tables"
  ],
  "properties": {
    "tables": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "headers",
          "rows"
        ],
        "properties": {
          "headers": {
            "type": "array",
            "minItems": 2
          },
          "rows": {
            "type": "array",
            "minItems": 1
          }
        }
      }
    }
  }
}

Any extracted payload violating required keys, types, bounds, or regex patterns returns schema_valid: false, exact validation_errors, and billed_micros: 0.

Executable REST, Remote /mcp & treg hub Snippets

curl -fsSL -X POST "https://scrape.fastmesh.dev/v1/extract" \
  -H "Content-Type: application/json" \
  -d '{
    "content_text": "<table><thead><tr><th rowspan=\"2\">Plan</th><th colspan=\"2\">Pricing</th></tr><tr><th>USD</th><th>Credits</th></tr></thead><tbody><tr><td>Starter</td><td>$15</td><td>1,000</td></tr><tr><td>Growth</td><td>$59</td><td>5,000</td></tr></tbody></table>",
    "format_hint": "html_table"
  }'

curl -fsSL -X POST "https://scrape.fastmesh.dev/mcp" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"scrape_table","arguments":{"url":"https://example.org/rates"}}}'

Hard guarantee: fake-200 CAPTCHA/Turnstile shells, login walls, encrypted PDFs, empty results, schema mismatches, and SSRF HTTP 422 blocks always return billed_micros: 0.

Test Schema-Validated Extraction Live in 5 Seconds

Paste any public URL, HTML table, JSON-LD, CSV, or fake-200 shell at scrape.fastmesh.dev or top up once with never-expiring Creem prepaid credits ($15 Starter / $59 Growth / $199 Scale — $0/mo recurring).

Frequently Asked Questions

How does Scrape-Anything flatten two-row `<thead>` headers?

When a table has multiple header rows with `colspan` and `rowspan`, the 2D grid tracks parent group labels above child columns and combines distinct header segments into a clean, deduplicated key per column.

Can I submit raw HTML directly without a public URL?

Yes. Send `content_text` with `content_type: "text/html"` and `format_hint: "html_table"` to `/v1/extract` or the `scrape_table` MCP tool.

What if a page contains zero tables when I require one?

Attach `minItems: 1` on `tables` in `json_schema`. If no table exists, validation returns `schema_valid: false` and `billed_micros: 0`.

Related Structured Extraction Guides

Explore all 32 Scrape-Anything Technical Guides or inspect the machine-readable llms.txt index.