Extract HTML Tables to GitHub-Flavored Markdown in Python
Turn multi-column HTML tables into clean Markdown pipe tables ready for LLM comparison prompts, Pandas ingestion, or automated reports.
Why this breaks in production
HTML tables hold the highest-value structured data on the web: SaaS pricing matrices, benchmark comparisons, API error codes, and financial disclosures. Yet standard text extractors flatten `<tr>` and `<td>` cells into unreadable space-separated mush.
Preserving table rows as GitHub-Flavored Markdown (`| Col A | Col B |`) allows LLMs to reason across columns accurately without losing row-to-column alignment.
Recommended Engineering Approach
Call CleanSnap from Python `requests`
Send a `POST` request with `stripNav: true` and `stripCookieBanners: true` to isolate the page content including tables.
Verify pipe escaping and column padding
CleanSnap automatically escapes literal `|` characters inside cells (`\|`) and pads uneven row lengths so Markdown renderers never break.
Pass the Markdown table straight into structured LLM extraction
Prompt GPT or Claude with the Markdown table to output strict JSON pricing objects or CSV rows.
Working Code Example
import requests
resp = requests.post(
"https://usecleansnap.com/api/v1/extract",
json={
"url": "https://example.com/pricing",
"stripCookieBanners": True,
"stripNav": True,
"includeMetadata": True,
},
timeout=15,
)
resp.raise_for_status()
data = resp.json()
# Extract only Markdown table lines
table_lines = [
line for line in data["markdown"].splitlines()
if line.strip().startswith("|")
]
print("\n".join(table_lines))Test this workflow in the CleanSnap Playground
Pre-load the Sample Pricing Page or paste your own URL to inspect clean Markdown, token savings, and auto-generated cURL / Node / Python / MCP code.
Common Edge Cases & Pitfalls
- Unescaped `|` characters inside a table cell (e.g., `string | number`) break Markdown column counts if not replaced with `\|`.
- Nested `<p>` or `<ul>` elements inside `<td>` cells create broken newlines unless flattened to single-line cell text.
- Layout tables from legacy websites may contain zero semantic headers; always inspect the first row before parsing into DataFrames.
Frequently Asked Questions
Does CleanSnap convert HTML `<table>` elements automatically?
Yes — `<table>`, `<thead>`, `<tbody>`, `<tr>`, `<th>`, and `<td>` are converted directly into valid GitHub-Flavored Markdown tables.
Can I test table extraction right now without writing code?
Yes — click the 'Sample Pricing Page' preset in the homepage Playground to see a live HTML pricing table converted to Markdown.
Does CleanSnap require any Python SDK installation?
No special SDK is required; standard `requests` or `httpx` works out of the box.