DEV Community

Charles
Charles

Posted on

How to Extract Structured Data from Any Website Using AI Extraction

How to Extract Structured Data from Any Website Using AI Extraction

Traditional web scraping means writing selectors. One CSS class change and everything breaks.

AI extraction changes this.

The Old Way

// Fragile: depends on HTML structure
const title = document.querySelector(".product-title h1 span").innerText;
const price = document.querySelector(".price-amount .current").innerText;
Enter fullscreen mode Exit fullscreen mode

The New Way

// Robust: describe what you want
const result = await client.scrape({
  url: "https://example.com/product",
  extraction: { mode: "llm", schema: { title: "Product name", price: "Current price in USD", rating: "Average rating out of 5" } }
});
Enter fullscreen mode Exit fullscreen mode

Benefits

  • Selector-free: No CSS selectors to maintain
  • Structure-proof: Works even if the site redesigns
  • Flexible: Change what to extract without rewrites
  • Accurate: LLMs understand context

Try AI extraction with XCrawl API

Top comments (0)