Leanpub Header

Skip to main content

Web Data for LLMs

Clean Markdown, Validated JSON and RAG-Ready Chunks from Any Website

Web Data for LLMs
This book is 25% completeLast updated on 2026-11-09

Turn any web page into clean Markdown, validated JSON and RAG-ready chunks with short Python programs, and stop paying your LLM to read navigation menus.

Minimum price

$7.99

$14.99

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
About

About

About the Book

Every useful LLM application eventually needs data from the web: product docs for a support bot, articles for a research agent, today's prices for a pricing tool. Most tutorials stop at "fetch the page and paste it into the prompt". That works for a demo and breaks in production: you pay for every tag the model reads, menus and cookie banners pollute your embeddings, and sites time out, rate-limit you or hide the real data in JSON.

This book is the missing middle. In short Python programs you can read in one sitting, it shows how to turn any web page into clean, structured, validated input for language models: polite fetching with timeouts, retries and robots.txt; HTML to clean Markdown with measured token savings; structured data you get for free (JSON-LD, Open Graph); schema-first extraction with Pydantic; letting an LLM extract fields and checking its work; chunking for RAG; crawling whole sites; and watching pages for changes.

Published in progress: chapters 1 to 3 are ready now, the free sample includes the preface and chapters 1 and 2, and every buyer gets every new chapter for free as it is released.

Author

About the Author

Rowan Hale

Rowan Hale writes practical guides on getting clean, structured data from the web into LLM applications: fetching, cleaning, extraction and RAG pipelines in plain Python.

Contents

Table of Contents

Preface

  1. Who this book is for
  2. How this book is built
  3. The plan
  4. Code and updates

Why LLMs Need Clean Web Data

  1. Three costs of dirty input
  2. The pipeline this book builds
  3. What “clean” means here
  4. A note on responsibility

Fetching Pages Politely

  1. Install
  2. 1. Always set a timeout
  3. 2. Identify yourself
  4. 3. Retry only what is worth retrying
  5. 4. One delay per host, not per request
  6. 5. Check robots.txt once per host
  7. Putting it together
  8. What we did not do (yet)
  9. Checklist

From HTML to Clean Markdown

  1. The five steps
  2. 1. Parse once, with a forgiving parser
  3. 2. Remove the noise
  4. 3. Absolute links
  5. 4. Find the main content
  6. 5. Convert and tidy
  7. The result
  8. Look before you trust
  9. Checklist

Appendix: Full Code

  1. requirements.txt
  2. fetch.py (Chapter 2)
  3. clean_markdown.py (Chapter 3)

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub