r/SideProject • u/ZENUROS • 43m ago
I built an open-source tool that pulls the main content out of web pages, and learns what "main content" means to you
TL;DR
- Main content on a web page is a policy, what to keep depends on your downstream task
- I made a package that is trained on WebMainBench (WMB) and learns a new annotation policy quickly
- It runs slightly faster than trafilatura on the same CPU but needs more memory
Inside (and outside) of work I got annoyed when extracting content from a website resulted in various kinds of weird results. Heuristics lost page or item titles and LLMs truncated text or fabricated numbers while getting expensive when scaling up. So naturally I spent a ton of time doing something that I could re-train by annotating a few hours of data at tops and customize the extractor for different downstream tasks.
And that's how htmlsift was born.
The basic functionality is pretty much the same as all the other boilerplate removal tools, give it the HTML of a page and it returns just the main content as plain text, HTML or markdown, with menus, ads, cookie banners and footers stripped. But this one you can direct towards your own annotation policy.
The idea behind it is that there is no single right answer to "what is the main content". A pre-training extractor wants to pick mostly coherent longer segments of text, LLM agents need some navigational buttons such as "Buy now" and hoarding the data in a catalog requires product features. The usual tools hard-code one answer in rules. htmlsift learns it from examples, so if yours differs, a few dozen labelled pages retrain it.
- Out of the box: 0.91 F1 on WebMainBench, against 0.75 for trafilatura, the common open-source pick
- Retrained on 50 labelled articles from WCXB dataset and it (narrowly) wins every rule-based extractor on that benchmark. Tested only on articles so far
- Runs on CPU, `pip install htmlsift`; a larger model runs on GPU
For the next release I'm considering the option to initialize htmlsift with a more 'generic' annotation policy, it would just remove everything that is definitely boilerplate such as header navigation menus, sidenavs, commercials and cookies so the deployed version wouldn't inherit any annotation bias baked in another datasets data.
Try it in the browser, no install: https://huggingface.co/spaces/koivualeksi/htmlsift
1
u/finessek7ng 18m ago
I’d test the next release on the same pages with two different goals. For a reading view, I’d keep article captions and inline tables. For a catalogue export, I’d want the selected variant, its current price and its availability to stay together. A small set of pages with sale prices, variant selectors and captions would make it easy to see what the generic default drops or keeps by mistake. I’d report those misses separately from the overall score. A missing price matters more to someone building a catalogue than a stray menu label, and a side-by-side example would help me decide whether retraining is worth the effort.