LLM web scraping for RAG and agents
LLM web scraping turns live web pages into clean Markdown or JSON a language model can read, for RAG pipelines, grounding and agent tool calls. Zenrows Fetch returns a URL as Markdown in one request, protected and JavaScript-heavy pages included, and the Zenrows MCP server lets Claude, Cursor and other agents make the same call themselves.
Updated
{
"url": "https://docs.example.com/api/rate-limits",
"fetched_at": "2026-10-17T09:14:03Z",
"format": "markdown",
"markdown": "# Rate limits\n\nEach API key can run 50 concurrent requests.\n\n## Retry headers\n\n| Header | Meaning |\n|---|---|\n| Retry-After | Seconds to wait before the next call |\n\nSee [Errors](https://docs.example.com/api/errors).",
"chunks": [
{ "id": "rate-limits#0", "heading": "Rate limits", "chars": 58 },
{ "id": "rate-limits#1", "heading": "Retry headers", "chars": 132 }
],
"links": [
"https://docs.example.com/api/errors",
"https://docs.example.com/api/authentication"
]
}
markdown string; your pipeline adds URL, timestamp and chunk ids before embedding or prompting.What LLM web scraping is used for
LLM pipelines read the web twice: before the question, indexing pages into a vector store; during it, when a model or agent opens a page it just chose.
| Job | Data you collect | Typical sources |
|---|---|---|
| URL to Markdown for a prompt | A page's body as Markdown, headings, tables and links kept | Docs sites, changelogs, pricing pages, |
| RAG ingestion | Markdown chunks, source URL, fetch time | Developer docs, regulator guidance, standards bodies, |
| Grounding at query time | Current text of the pages to cite | |
| Agent tool calls | A scrape or extract result mid-task | Any URL the agent opens |
| Structured context for tools | Named fields as JSON | |
| Index refresh | A new copy of each indexed URL, diffed with the last | The same URL list, daily or weekly |
Why web data breaks LLM pipelines
Most RAG and agent failures trace back to the page the model got.
A blocked request or empty shell looks normal, so the model answers from memory and nobody notices.
Scripts, styles and class names eat the token budget
Markdown output keeps headings, tables and links
An empty <div id="root">
Adaptive Stealth Mode renders in a browser when needed
A Cloudflare or DataDome challenge instead of the article
Zenrows' stealth gets through Cloudflare, DataDome and Akamai
The assistant confidently quotes last quarter's pricing
Re-fetch with Batch on a schedule; re-embed what changed
A 400 KB HTML string, truncated
Markdown for reading, or Extract for JSON fields
How to scrape the web for LLMs
- Pick the output per job: Markdown for a model to read, Extract for named fields.
- Fetch the page with Markdown output and Adaptive Stealth Mode, which escalates only when needed.
- Chunk and keep the source: split on headings, store URL and fetch time per chunk for citations.
- Give agents the same tool through the MCP server, or the CLI from a terminal or coding agent.
# pip install requests
import re
from datetime import datetime, timezone
import requests
TARGET_URL = "https://docs.example.com/api/rate-limits" # any page you want to index
def fetch_markdown(url):
params = {
"apikey": "YOUR_ZENROWS_API_KEY",
"url": url,
"mode": "auto",
"response_type": "markdown",
}
r = requests.get("https://api.zenrows.com/v1/", params=params, timeout=120)
r.raise_for_status()
return r.text
def chunk_by_heading(url, markdown):
fetched_at = datetime.now(timezone.utc).isoformat()
parts = re.split(r"\n(?=#{1,3} )", markdown)
return [{"url": url, "fetched_at": fetched_at, "text": p.strip()}
for p in parts if p.strip()]
chunks = chunk_by_heading(TARGET_URL, fetch_markdown(TARGET_URL))
print(len(chunks), "chunks ready to embed")// Node 18+. A tool function any agent framework can register.
export async function readPage(url, { fields = false } = {}) {
const params = new URLSearchParams({
apikey: process.env.ZENROWS_API_KEY,
url,
mode: "auto",
});
if (fields) params.set("extract", "auto");
else params.set("response_type", "markdown");
const res = await fetch(`https://api.zenrows.com/v1/?${params}`);
if (!res.ok) throw new Error(`Zenrows ${res.status}: ${await res.text()}`);
return fields ? res.json() : res.text();
}npx -y @zenrows/cli init
zenrows fetch https://docs.example.com/api/rate-limits --output markdown
zenrows extract https://docs.example.com/api/rate-limits --autoparse
zenrows batch create docs-urls.jsonl --wait# Connect once
claude mcp add zenrows -e ZENROWS_API_KEY=YOUR_ZENROWS_API_KEY -- npx -y @zenrows/mcp
# Then ask:
Use Zenrows to read https://docs.example.com/api/rate-limits as Markdown. Answer my
question using only that page, quote the sentence you relied on, and give me the URL.Which Zenrows product fits
- Turn one URL into prompt-ready Markdown FetchLLM-ready Markdown in one request
- Hand a tool JSON without selectors ExtractThe page's data as structured JSON
- Re-read thousands of indexed URLs on schedule BatchOne job, results by webhook or download
- Let Claude, Cursor or Codex read pages mid-task MCP ServerThe agent calls scrape and extract as MCP tools
- Wire web access into your agent framework Agent ToolkitSkills and plugins that pick the right Zenrows call per task
What success looks like
| Measure | What good looks like | How to check it |
|---|---|---|
| Content completeness | The Markdown holds what a visitor sees, tables included | Weekly spot-check against the live site |
| Tokens per page | Markdown at a fraction of the raw HTML size | HTML against Markdown token counts per URL |
| Failed reads | Blocked or empty pages retried or flagged, never embedded | Log non-200s and pages under a minimum length |
| Index freshness | Every URL re-read within your refresh window | Alert on stale fetched_at per chunk |
| Citation accuracy | Each answer's URL contains the quoted claim | String-match quotes against stored chunks |
LLM web scraping FAQ
-
Two things. Scraping for LLMs prepares pages as model input: Markdown to read, JSON for tools, each with a source URL. Scraping with LLMs uses a model instead of CSS selectors to pull fields. Zenrows covers both: Fetch with Markdown output, and Extract for fields without selectors.
-
GET
https://api.zenrows.com/v1/with yourapikey, theurland Markdown output on. The body is the page as Markdown, headings, lists, tables and links kept. With Adaptive Stealth Mode, Zenrows renders or applies stealth only when needed. In a terminal:zenrows fetch URL --output markdown. -
Grounding gives the model source text at answer time, so it quotes facts instead of recalling them. The web is usually the freshest source: current pricing, today's news, the latest regulation. Fetch the pages the answer needs, pass the Markdown in, and ask for a URL per claim.
-
Connect the Zenrows MCP server once. Claude, Cursor, Codex, Windsurf, Gemini CLI and other MCP clients then see
scrapeandextractand call them when a task needs a page. The remote server ishttps://mcp.zenrows.com/mcp, with your API key as a Bearer token; Claude can also use OAuth sign-in. -
Markdown when the model reads and reasons: articles, docs, policies, long descriptions. JSON when code consumes it: prices, ratings, dates, addresses. Many pipelines do both: Markdown to the vector store, Extract fields to a database.
-
Yes. Fetch is plain HTTP, callable from a tool function like the Node.js example. The Zenrows docs have guides for LangChain, LlamaIndex, CrewAI, Mastra, the OpenAI Agents SDK and the Claude Agent SDK, and any MCP framework can use the remote server.
-
Store fetch time per chunk and re-read URLs as fast as each source changes: news daily, docs weekly, policies monthly. Run one Batch job, hash each page's Markdown, re-embed only changed hashes. Flag pages that come back empty or much shorter instead of overwriting old chunks.