KROMA SYSTEM / 01ENGINEERING DIGITAL GROWTH

BOOT_SEQUENCE // KROMACODE.TECH

Mapping the system000
CREATIVE SYSTEMSWEB / AI / GROWTHREADY WHEN YOU ARE
KC
KROMA CODE
// kromacode.tech
// ROUTE_TRANSITION_SYS :: BLOG/AUTONOMOUS WEB SCRAPING AI AGENTS/
STATUS: 200 OK
LIVE DEV GAG / REALITY CHECK:

"Yash reviewing pull requests at 3:14 AM again..."

COMPILING UI NODES0%
// KROMA CODE BLOG :: AI AUTOMATION

Building Resilient Web Scraping Agents with Playwright and LLM Parser Fallbacks

Suhaan Singh Kushwahaβ€’ 10 min readβ€’July 22, 2026
πŸ’‘ ARTICLE EXECUTIVE SUMMARY: "Traditional web scrapers break when HTML class names change. Learn how to combine headless Playwright browser automation with LLM element fallback locators for 99.9% scraper uptime."

1. The Fragility of DOM Selectors

Traditional web scrapers relying on hardcoded CSS selectors (e.g. div.product-card > span.price-tag) break whenever target websites update their frontend framework, re-generate Tailwind utility classes, or deploy new UI components. For automated business intelligence, pricing engines, and lead collection, fragile scrapers cause continuous pipeline downtime.

2. Self-Healing AI Scraper Architecture

At Kroma Code, we build self-healing scrapers using Playwright and LLM fallback locators. When a CSS selector fails to locate a target DOM node, the scraper captures a clean snapshot of the DOM tree, sends the semantic structural snippet to a fast LLM, and receives an updated selector dynamically.

3. Code Example: Self-Healing Selector in Python

from playwright.async_api import async_playwright
import httpx

async def extract_product_price(page, primary_selector: str):
    try:
        # 1. Attempt primary CSS selector execution
        element = await page.wait_for_selector(primary_selector, timeout=3000)
        return await element.inner_text()
    except Exception:
        print("[WARN] Primary selector failed. Triggering LLM Self-Healing Locator...")
        
        # 2. Capture sanitized DOM snippet
        body_html = await page.evaluate("document.body.innerText.slice(0, 3000)")
        
        # 3. Query LLM to identify target content
        async with httpx.AsyncClient() as client:
            res = await client.post("https://api.openai.com/v1/chat/completions", json={
                "model": "gpt-4o-mini",
                "messages": [{
                    "role": "user", 
                    "content": f"Extract price from text snippet: {body_html}"
                }]
            }, headers={"Authorization": "Bearer YOUR_SECRET_KEY"})
            
            return res.json()["choices"][0]["message"]["content"]
      

4. Production Impact

Self-healing scraping pipelines operate with over 99.9% uptime, eliminating manual code fixes when third-party sites update their markup.

// INTERCONNECTED TOPICAL LINKS
Written by Suhaan Singh Kushwaha (Founding Engineer at Kroma Code, Lucknow)
Consult With Author