Trafilatura Drops 75% of Table Text

🔧 AI Tools 2026-11-27 6 min read

A RAG index built with one extraction call loses its tables and code blocks, and nothing in the output flags it until retrieval misses numbers.

📜 Table of Contents

📖 Keep reading

Trafilatura kept a median of 25% of the table text on the 27 article pages tested today. On the worst page it kept 11.7%. Plain BeautifulSoup get_text kept 97.6%. If a RAG pipeline turns blog posts and docs into chunks with one extraction call, tables are the part that disappears first, and nothing in the output says so.

The token savings everyone quotes for readability extraction are real and measurable: 31.6% fewer input tokens across the same 27 pages. The question is what got dropped to get there.

What was measured

The headline numbers

ExtractorTotal tokens, 27 pagesMedian per pageMedian latency
BeautifulSoup get_text94,6922,85624 ms
readability-lxml60,9981,74239 ms
trafilatura default64,7601,86727 ms
trafilatura favor_precision63,1171,80326 ms

Median reduction against the naive baseline: 29.7% for trafilatura, 33.3% for readability. The extremes matter more. The Verge FCC article went from 1,647 tokens to 341 under trafilatura, a 79.3% cut. Cloudflare post on agent search went from 4,431 to 1,975. GitHub post about developer gifts went from 2,918 to 897.

Some of that is menu, footer, cookie banner and related-links furniture. Some of it is not.

Tables: three quarters of the text is gone

Five pages had tables with at least 40 characters of text. Comparing what each extractor kept:

PageTable chars in HTMLBeautifulSoupreadabilitytrafilatura
huggingface.co/blog/training-swarms73392.8%92.8%11.7%
huggingface.co/blog/nvidia/nemotron-parse357100%100%19.5%
huggingface.co/blog/ggml-org/llamacpp-amd-bench174100%100%25.0%
github.blog application modernization1,23195.7%95.7%50.5%
blog.cloudflare.com/ruby2shell-waf-protection1,36997.6%97.6%66.1%

Median retention on those five pages: 97.6% for BeautifulSoup, 97.6% for readability, 25.0% for trafilatura. Trafilatura table handling is configurable and does better on simple two-column layouts, but on these five it flattened rows into a running string or dropped rows that repeat identical cells. A benchmark table where every row shares the same model name is exactly the shape it loses.

This is the failure that hurts a RAG index quietly: the chunk that should read llama.cpp on AMD, 1,024 tokens, 41 tokens per second arrives as prose fragments, the embedding points at nothing useful, and recall drops on the only queries that needed numbers.

Code blocks mostly survive, with two exceptions

Nine pages contained pre blocks worth measuring. BeautifulSoup and readability kept a median 93.5% of the code text. Trafilatura kept 91.7%, and two pages fell off a cliff: the Hugging Face training-swarms post kept 39% of its code, and Cloudflare search-for-agents post kept 82.8%. In both cases the lost lines were indented snippets that trafilatura re-flowed into paragraph text, so the Python semantics disappeared while the words stayed.

If the corpus is tutorial content where code is the answer, that is the same class of bug as the table loss, just less frequent. Extract code separately, or post-check it.

Readability fails in the opposite direction

Readability removes the most boilerplate, and it also removes content it cannot classify. Two examples from the run: GitHub post about developer gifts, 3,386 tokens naive against 1,137 after readability; The Verge FCC article, 1,647 against 310. A reader would call those truncations, not cleaning. Readability is tuned for pages with an article body and a clear main element; landing pages and category templates lose whole sections.

Trafilatura was more conservative on the same pages: 1,352 and 341. Neither is right for a page whose main content is a card grid, which is most vendor documentation hubs.

The pipeline that keeps tables

Run the prose extractor for the body, pull tables out of the raw HTML separately, append them as Markdown. Two dependencies, no schema guessing:

import io
import pandas as pd
import trafilatura

def extract_document(html: str) -> str:
    body = trafilatura.extract(
        html, include_tables=False, include_comments=False
    ) or ""
    tables = []
    try:
        for df in pd.read_html(io.StringIO(html)):
            if df.shape[0] >= 2 and df.shape[1] >= 2:
                tables.append(df.to_markdown(index=False))
    except ValueError:
        pass  # no tables on this page
    parts = [body.strip()] + tables
    return nn.join(p for p in parts if p)

pandas.read_html needs lxml and tabulate. On the five table pages above this recovered the full table text while keeping trafilatura body extraction, at roughly 1 to 40 ms per page. The output is Markdown, so the chunker sees pipe tables and the model sees column headers on every row.

Two checks worth adding before trusting either path:

  1. Count tokens before and after. A page whose extraction drops more than 40% of the naive token count is a candidate for manual inspection, not automatic approval.
  2. Verify the page's own h2 headings appear in the output. If the heading is missing, the extractor picked the wrong container, which is what happened on The Verge.

Does the 31.6% saving justify the work

On these 27 pages, 29,932 input tokens disappear with trafilatura. At one dollar per million input tokens that is three cents. At ten thousand pages a month the same ratio is roughly 11 million tokens, so the saving is real but it is not where a budget dies. The reason to strip boilerplate is retrieval quality: navigation text and cookie notices embed into vectors that then compete with the actual answer at query time.

The reason to keep tables is the same argument in reverse. A pipe table adds tokens and pays them back the first time a user asks for a number.

FAQ

Is trafilatura still the right default for article text? Yes for prose: it came within four percentage points of readability token cut while running faster and being less destructive on technical posts. Add table extraction and a token-count check and it is a solid default.

Why not BeautifulSoup get_text everywhere? Because 94,692 tokens against 64,760 is 46% more input on the same 27 pages, and a large share of the extra is menus, cookie banners and comment sections that pollute embeddings.

How to measure retention on a different corpus? Pull 20 URLs from a sitemap, extract the text inside pre and table elements from the raw HTML, compute 5-gram overlap against each extractor output. The script is 30 lines and it catches failures a spot check misses.

Related

Related Articles
2026-08-01
AI Visibility Checker 2026: Track Whether ChatGPT and Perplexity Cite Your Site
2026-08-13
AI Terminal Assistant 2026: 6 Tools That Bring AI to Your Command Line
2026-07-25
Free AI Chatbots 2026: What Each One Actually Limits
2026-08-12
LLM Development Tools 2026: The 12 Libraries You Will Actually Use, Ranked by Stage
2026-08-24
Best AI Meeting Notetaker in Nagoya 2026: 6 Tools for Manufacturing Professionals
2026-08-18
Best AI Transcription Tool in Manila 2026: 6 Tools for BPO, Court Reporting and Media

Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.

💬 Comments (0)

No comments yet. Be the first!

Login to comment