chapter twelve

12 AI-powered web scraping data pipelines in action

 

In Chapter 10 you scraped product pages by hand. In Chapter 11 you replaced the fragile parts with AI: you used a search API and an LLM to discover URLs, cleaned HTML aggressively to control cost, and extracted structured fields with a schema-driven prompt. Each of those was a working piece of code, but they lived in separate notebook cells. You ran them one at a time, on one product, and read the output with your eyes.

That is exactly how most data work starts: a pile of useful snippets. The gap between a pile of snippets and a pipeline is the difference between "it worked when I tried it" and "it runs unattended across 450 products and I trust the output." Closing that gap is what this chapter is about.

We are going to take the functions you already wrote and reshape them into agents: small, single-purpose units that each own one job, accept a clear input, and return a clear output. Then we will chain those agents together into one pipeline, add the unglamorous-but-essential machinery that keeps a pipeline alive in production, and run the whole thing on a batch of RuckZone products.

By the end, you will have a pipeline you could actually schedule, plus a mental model for building pipelines like this for any data source.

12.1 From snippets to a pipeline

12.1.1 What we mean by "agent"

12.1.2 Why agents instead of one big function

12.2 Designing the data contract

12.3 The four agents

12.3.1 Shared infrastructure: logging and retries

12.3.2 Agent 1: URL discovery

12.3.3 Agent 2: fetch and clean

12.3.4 Agent 3: AI extraction

12.3.5 Agent 4: validate and map

12.4 Orchestrating the pipeline

12.5 Running the pipeline end to end

12.6 Working the review queue

12.7 What you can reuse

12.8 Lab

12.9 Lab answers