Back to articles
I Replaced 200 Lines of CSS Selectors With 3 Lines of AI — Here's the Code

I Replaced 200 Lines of CSS Selectors With 3 Lines of AI — Here's the Code

via Dev.to TutorialAlex Spinov

Last month I was scraping product data from 15 different e-commerce sites. Every site had different HTML. Every site broke my selectors every few weeks. I was spending more time maintaining scrapers than actually using the data. Then I tried something stupid: I sent the raw HTML to Claude and said "extract the product name, price, and rating." It worked. On every site. Without a single CSS selector. The Old Way (200+ lines per site) # site1.py price = soup . find ( ' span ' , class_ = ' price-tag__amount ' ). text . strip () name = soup . find ( ' h1 ' , { ' data-testid ' : ' product-title ' }). text rating = soup . find ( ' div ' , class_ = ' star-rating ' ). get ( ' aria-label ' ) # site2.py (completely different selectors) price = soup . select_one ( ' .pdp-price .sale-price ' ). text name = soup . select_one ( ' #productName ' ). text rating = soup . select_one ( ' .ratings-count span ' ). text # site3.py (different again) # ... you get the idea 15 sites × 15 selectors each = 225 C

Continue reading on Dev.to Tutorial

Opens in a new tab

Read Full Article
2 views

Related Articles