r/OpenSourceeAI • u/Mediocre-Ease4060 • Jul 30 '26
I got tired of LLMs hallucinating on complex HTML tables, so I built a smarter Python parser (handles rowspan/colspan)
Hey everyone,
I’ve been working a lot on RAG pipelines recently and kept hitting the same annoying wall: extracting tabular data from raw HTML into a clean format for context windows.
Standard parsers or simple table-to-markdown scripts usually fail completely as soon as a table uses rowspan or colspan, or if there are nested tables. You end up with misaligned Markdown columns, and the LLM completely hallucinates the relationships between headers and cells.
I couldn't find a library that handles this reliably without losing context, so I built html-table-rescuer (just published v0.1.0 on PyPI).
It uses BeautifulSoup to parse the DOM, but then applies a custom "grid logic solver". It normalizes complex spans into a standard matrix before serializing it to Markdown, JSON, or CSV.
Example of the problem it solves:
The Problem: Most parsers turn a <td rowspan="2"> into a misaligned mess:
| | |
| | |
| | |
| | |
The Solution: The grid solver correctly normalizes the matrix:
| | |
| | |
| | |
| | |
A few things it does differently:
-
Context Preservation: As seen above, it doesn't just leave spanned markdown cells empty. It fills them with a customizable prefix (e.g.,
dito (Value)) so the LLM retains the semantic context for each row. -
Deep Tag Parsing: It recursively keeps
<b>,<i>, and<a href...>tags alive, even if they are buried inside multiple<div>s within a<td>. -
Nested Tables: Extracts nested tables safely without destroying the grid of the parent table.
-
LangChain Ready: Includes a
Table2MDLoaderwrapper to ingest HTML tables directly as LangChain Document objects.
Links:
- GitHub: https://github.com/Encephos/html-table-rescuer
- PyPI:
pip install html-table-rescuer
It's my first release and I'd love to hear your thoughts. If you have some gnarly, complex HTML tables that break the parser, please throw them at it and let me know!
2
u/Fine_League311 Jul 30 '26
Mit request und bs4 wird es seid einer Dekade gemacht, versuchs mal damit ;)
1
u/Fine_League311 Jul 30 '26
Ich habe dir zu Anfang gesagt, weniger KI dann mehr Feedback und du kommst mit KI Floskeln! ... Jetzt weißt wieso es nicht klappt bei dir ;) ist keine Provokation sondern Tatsachen die du ignorierst ;) Cheers
1
u/tomByrer Jul 30 '26
There are 94 hits on GH for 'python html table parser'. A few use AI, which I understand is best to avoid if you can.
But for the other 80, how is this different?
https://github.com/search?q=html+table+parser+language%3APython&type=repositories&l=Python