Skip to main content

A robust HTML table parser for Python with full rowspan/colspan and multi-header support

Project description

tabulate-html

A robust, professional-grade HTML table parser for Python, designed specifically for complex real-world web tables. It fully supports rowspan, colspan, multi-row hierarchical headers, merged cells, and concatenation of fragmented HTML snippets.

While many lightweight table parsers fail on merged cells, tabulate-html uses a precise 2D matrix mapping to handle them perfectly — making it an ideal choice for web scraping, data extraction, and structured crawling.

PyPI version Python versions License: MIT Tests Coverage

中文文档

Features

  • Accurate handling of arbitrary rowspan and colspan (outperforms pandas.read_html and most other libraries on complex tables)
  • Support for multi-row hierarchical headers (automatically merged as Level1_Level2_Level3)
  • Concatenation of multiple table fragments (perfect for paginated or dynamically loaded tables)
  • Configurable extraction strategies:
    • TEXT_AND_LINKS: plain text + appended links/images
    • RAW_HTML: preserve original cell HTML
    • STRIP_TAGS: pure text only
  • Comprehensive logging and production-ready error handling
  • Full type hints and clean, maintainable code

Installation

pip install tabulate-html

## Quick Start

```python
from tabulate_html import parse_html_tables

html = """
<table>
  <tr><th>Name</th><th colspan="2">Contact</th></tr>
  <tr><th>Age</th><th>Phone</th><th>Email</th></tr>
  <tr><td rowspan="2">John Doe</td><td>30</td><td>138...</td><td>john@example.com</td></tr>
  <tr><td>31</td><td>139...</td><td>john.new@example.com</td></tr>
</table>
"""

data = parse_html_tables(html, header_rows=[0, 1])
print(data)
Output:
[
  {
    "Name_Age": "John Doe",
    "Contact_Phone": "138...",
    "Contact_Email": "john@example.com"
  },
  {
    "Name_Age": "John Doe",
    "Contact_Phone": "139...",
    "Contact_Email": "john.new@example.com"
  }
]

Advanced Usage

from tabulate_html import TableParser, ParseStrategy

parser = TableParser(
    strategy=ParseStrategy.TEXT_AND_LINKS,  # Extract text and append links/images
    key_separator="-",                      # Use hyphen for header keys
    tag_separator=" "                       # Join multi-text segments with space
)

result = parser.parse(html_snippets, header_rows=[0, 1, 2])  # Support 3-level headers
json_output = parser.to_json(result)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tabulate_html-0.1.1.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tabulate_html-0.1.1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file tabulate_html-0.1.1.tar.gz.

File metadata

  • Download URL: tabulate_html-0.1.1.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for tabulate_html-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ac841341e0ac91020e31d508aa9765a718a1b83b47ca3e52a6039724c465993e
MD5 710d820e4179c56bc762a8ca0f2ba884
BLAKE2b-256 3bad29397f14de91c98dd3c86e0306904c807b19f4fe64815de39af00c3f1f82

See more details on using hashes here.

File details

Details for the file tabulate_html-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: tabulate_html-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for tabulate_html-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8e772672291da44142ad4aecd94a8a6a7979422e23a5c63becacd6177db4e3b7
MD5 030f3365b93087911545a88d670ee535
BLAKE2b-256 911a4f3979d05da9dcd17368c3786eb00c3e6ae8398365f0954f615aeaecf881

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page