---
title: "LLM web scraping for RAG and agents"
description: "LLM web scraping API that turns live pages into Markdown or JSON for RAG, grounding and agents. Docs, news and product pages, plus an MCP server."
canonical: https://www.zenrows.com/use-cases/llm-web-scraping
updated: 2026-10-18
---

# 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](/products/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.

## Sample output: one page, ready for a model

```json
{
  "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"
  ]
}
```

Illustrative. Fetch returns the `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, GitHub READMEs |
| RAG ingestion | Markdown chunks, source URL, fetch time | Developer docs, regulator guidance, standards bodies, Wikipedia |
| Grounding at query time | Current text of the pages to cite | Reuters, AP News, vendor pricing pages, government sites |
| Agent tool calls | A `scrape` or `extract` result mid-task | Any URL the agent opens |
| Structured context for tools | Named fields as JSON | Amazon product pages, company websites, Indeed job posts |
| 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.

| What breaks | What it looks like | How Zenrows handles it |
|---|---|---|
| Raw HTML in the context | Scripts, styles and class names eat the token budget | Markdown output keeps headings, tables and links |
| JavaScript-rendered pages | An empty `<div id="root">` | Adaptive Stealth Mode renders in a browser when needed |
| Blocked fetches | A Cloudflare or DataDome challenge instead of the article | Zenrows' stealth gets through Cloudflare, DataDome and Akamai |
| Stale index | The assistant confidently quotes last quarter's pricing | Re-fetch with Batch on a schedule; re-embed what changed |
| Output a tool cannot parse | A 400 KB HTML string, truncated | Markdown for reading, or Extract for JSON fields |

## How to scrape the web for LLMs

1. **Pick the output per job**: Markdown for a model to read, Extract for named fields.
2. **Fetch the page** with Markdown output and Adaptive Stealth Mode, which escalates only when needed.
3. **Chunk and keep the source**: split on headings, store URL and fetch time per chunk for citations.
4. **Give agents the same tool** through the MCP server, or the CLI from a terminal or coding agent.

```python Python
# 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")
```

```javascript Node.js
// 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();
}
```

```bash CLI
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
```

```text Claude Code (MCP)
# 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

| If you need to | Use | Why |
|---|---|---|
| Turn one URL into prompt-ready Markdown | [Fetch](/products/fetch) | LLM-ready Markdown in one request |
| Hand a tool JSON without selectors | [Extract](/products/extract) | The page's data as structured JSON |
| Re-read thousands of indexed URLs on schedule | [Batch](/products/batch) | One job, results by webhook or download |
| Let Claude, Cursor or Codex read pages mid-task | [MCP Server](/mcp) | The agent calls `scrape` and `extract` as MCP tools |
| Wire web access into your agent framework | [Agent Toolkit](/agents) | Skills 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

### What is LLM web scraping?

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.

### How do I convert a URL to Markdown with an API?

GET https://api.zenrows.com/v1/ with your apikey , the url and 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 .

### What is LLM grounding, and where does web data fit?

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.

### How do AI agents scrape websites through MCP?

Connect the Zenrows MCP server once. Claude, Cursor, Codex, Windsurf, Gemini CLI and other MCP clients then see scrape and extract and call them when a task needs a page. The remote server is https://mcp.zenrows.com/mcp , with your API key as a Bearer token; Claude can also use OAuth sign-in.

### Should I give the model Markdown or JSON?

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.

### Does it work with LangChain, LlamaIndex and agent SDKs?

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.

### How do I keep a RAG index fresh?

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.

## Related use cases

- [AI agent browser](https://www.zenrows.com/use-cases/ai-agent-browser.md): A cloud browser your agent drives over MCP or CDP to log in, click and fill forms.
- [Deep research agent](https://www.zenrows.com/use-cases/deep-research-agent.md): An agent that reads dozens of live sources as Markdown, including protected pages, and cites every claim.
- [Chatbot training data](https://www.zenrows.com/use-cases/chatbot-training-data.md): Your website, help center and docs as clean Markdown for a chatbot knowledge base, refreshed on schedule.
- [AI training data](https://www.zenrows.com/use-cases/ai-training-data.md): Web corpora for pre-training and fine-tuning, collected as Markdown JSONL with a source URL on every document.
- [Content aggregation](https://www.zenrows.com/use-cases/content-aggregation.md): Articles, events, deals and listings from hundreds of websites, mapped to one schema and kept fresh.
- [AI web scraper](https://www.zenrows.com/use-cases/ai-web-scraper.md): Product, listing and article pages returned as clean JSON fields, with no selectors to write or repair.

Start free: https://app.zenrows.com/register. Docs: https://docs.zenrows.com

## Structured data



<script type="application/ld+json">
{"@context":"https://schema.org","@graph":[{"@type":"WebPage","@id":"https://www.zenrows.com/use-cases/llm-web-scraping#webpage","url":"https://www.zenrows.com/use-cases/llm-web-scraping","name":"LLM web scraping for RAG and agents","description":"LLM web scraping API that turns live pages into Markdown or JSON for RAG, grounding and agents. Docs, news and product pages, plus an MCP server.","isPartOf":{"@id":"https://www.zenrows.com/#website"},"inLanguage":"en","datePublished":"2026-10-18","dateModified":"2026-10-18","about":{"@type":"Thing","name":"llm web scraping"},"keywords":"llm web scraping, url to markdown api, webpage to markdown, llm grounding, web scraping for rag, mcp server web scraping, llm-ready web scraping api, web scraping for llm, ai agent web scraping","publisher":{"@type":"Organization","name":"Zenrows","url":"https://www.zenrows.com/"}},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://www.zenrows.com/"},{"@type":"ListItem","position":2,"name":"Use cases","item":"https://www.zenrows.com/use-cases"},{"@type":"ListItem","position":3,"name":"LLM web scraping for RAG and agents","item":"https://www.zenrows.com/use-cases/llm-web-scraping"}]},{"@type":"FAQPage","@id":"https://www.zenrows.com/use-cases/llm-web-scraping#faq","mainEntity":[{"@type":"Question","name":"What is LLM web scraping?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","name":"How do I convert a URL to Markdown with an API?","acceptedAnswer":{"@type":"Answer","text":"GET https://api.zenrows.com/v1/ with your apikey , the url and 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 ."}},{"@type":"Question","name":"What is LLM grounding, and where does web data fit?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","name":"How do AI agents scrape websites through MCP?","acceptedAnswer":{"@type":"Answer","text":"Connect the Zenrows MCP server once. Claude, Cursor, Codex, Windsurf, Gemini CLI and other MCP clients then see scrape and extract and call them when a task needs a page. The remote server is https://mcp.zenrows.com/mcp , with your API key as a Bearer token; Claude can also use OAuth sign-in."}},{"@type":"Question","name":"Should I give the model Markdown or JSON?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","name":"Does it work with LangChain, LlamaIndex and agent SDKs?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","name":"How do I keep a RAG index fresh?","acceptedAnswer":{"@type":"Answer","text":"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."}}]}]}
</script>
