Back to Case Studies

Universal DOM Homogeneity Scraper

Structure-Based Menu Extraction Without Per-Site Rules

ProductionFood & FMCGHospitalityJan 2022 – Sep 2022NLP, Knowledge Systems & Generative AI
95%
Menu dishes correctly extracted
4.1x
Faster menu processing
0
Site-specific rules or selectors
Any
Language: the method reads structure

My Role

Role
Algorithm author, solo engineer
Independent consulting
Team
Only ML developer in a 9+ startup
Stage reached
In production until contract ended
Key decisions
  • Find the menu by structural homogeneity, not keywords
  • Tree edit distance to tolerate near-identical items
  • Score candidate blocks to skip non-menu repeats

Approach at a Glance

Details
  1. 1DOM Tree and Structural Signatures
  2. 2Bottom-Up Pass: Finding Homogeneous Siblings
  3. 3Top-Down Pass: Choosing the Menu Block
  4. 4Field Mapping with Regex
  5. 5NLP Post-Processing

Executive Summary

A universal scraper that extracts restaurant menus from any website without writing a single site-specific rule. I designed the algorithm for a healthy-dining app in Estonia, where it fed restaurant menus into the app's food-intelligence pipeline.

It is built on one hypothesis: the items of a menu share the same structure. Every dish on a page is rendered by the same, or almost the same, HTML pattern. So instead of looking for words like "price" or for CSS classes that change from site to site, the algorithm looks for structural homogeneity: groups of elements in the page's DOM tree that are identical or very similar to each other. The largest, most consistent group is the menu.

The scraper extracted menu dishes with 95% accuracy and made menu processing 4.1x faster than building per-site scrapers or entering menus by hand. Because it relies on structure rather than text, it works on pages in any language. This was 2022, before ChatGPT, so there was no LLM to fall back on. The approach is pure algorithm, with regex and a light NLP classifier for post-processing. I designed and built it alone, as the only ML developer in the startup's team.


Client Profile

The client was a healthy-eating app in the Estonian market that lists restaurants with healthy dishes and scores them. Its whole proposition depended on having up-to-date menus from many restaurants, and those menus lived on the restaurants' own websites.

Those websites have nothing in common:

  • Every site is different: different builders, templates and markup. A scraper written for one restaurant breaks on the next, and on the same restaurant after a redesign.
  • No shared vocabulary: menus are in Estonian, English or Russian, with no standard labels for dishes, descriptions or prices.
  • Scale: writing and maintaining a scraper per restaurant, or typing menus in by hand, doesn't scale to a whole market.

The scraper had to work on a website it had never seen, with no configuration.


Technical Approach

  1. DOM Tree and Structural Signatures – The page is parsed into its DOM tree. Each subtree gets a structural signature built from its tag path and the sequence of tags and classes beneath it. The signature describes how an element is built, ignoring the text inside it.

  2. Bottom-Up Pass: Finding Homogeneous Siblings – Moving from the leaves up, the algorithm compares the signatures of sibling subtrees and groups those that are identical or nearly so. Menu items are rarely perfectly identical: one dish has a badge, another has no description, a third has a photo. So similarity is measured with tree edit distance, which tolerates small differences while still separating truly different elements.

  3. Top-Down Pass: Choosing the Menu Block – Moving from the root down, the algorithm looks for parents with enough near-identical children to pass a threshold. Pages contain other repeated blocks too, like navigation links, news, reviews and opening hours. Several candidate blocks are therefore scored, and the best one is chosen as the menu.

  4. Field Mapping with Regex – Inside each menu item, regular expressions map the parts to fields: dish name, description and price.

  5. NLP Post-Processing – A classifier cleans up the result. It filters out repeated blocks that aren't dishes, and detects menu categories and sections, such as starters, mains and drinks, so each dish lands in the right section.


Business Outcome

The app could collect menus from restaurant websites automatically, with no scraper to write or maintain per site. Dishes were extracted with 95% accuracy, menu processing was 4.1x faster than per-site scrapers or manual entry, and the same algorithm worked across layouts and languages. It ran in production in the app until the contract ended.

The project showed that a single, well-chosen structural hypothesis can replace hundreds of site-specific rules. It did so without any LLM, at a time when none was available.

Technologies

Web ScrapingDOM Tree AnalysisSubtree SignaturesTree Edit DistanceRegex Field MappingNLP Classification

Planning something similar?

Tell me about it on a short call. New projects can start within 2 weeks