When the Scraper Breaks Itself: Building a Self-Healing CSS Selector Repair System
A Python sidecar that watches your scraper fail, calls a local LLM, and fixes the problem before your users notice. The Problem with Fragile Selectors Production web scrapers have a hidden fragilit...

Source: DEV Community
A Python sidecar that watches your scraper fail, calls a local LLM, and fixes the problem before your users notice. The Problem with Fragile Selectors Production web scrapers have a hidden fragility: they depend on CSS selectors and XPath expressions authored against a snapshot of a third-party website's DOM. The moment the site redesigns its layout, renames a class, or restructures a table, those selectors silently return nothing — or, worse, return the wrong data. For a surf alert system that monitors dozens of forecast sources, this is a recurring operational problem. A selector like tr.forecast-table__row[data-row-name="wave-heigth"] (yes, a typo the upstream site just fixed) breaks at 3 AM. The scraper records a failure, the forecast pipeline stalls, and users stop receiving alerts for a beach they care about. An engineer wakes up to a Slack notification, digs through logs, finds the selector, pushes a fix, and deploys. The fix itself usually takes under five minutes. The detectio