---
title: "Web Crawling vs Web Scraping: Differences & Python Examples"
description: "Web crawling discovers pages; web scraping extracts data from them. How each works, a minimal polite crawler in Python, when you need which, whether AI agents need either, and the legal basics."
category: "guides"
url: https://keirolabs.cloud/blog/web-crawling-vs-web-scraping
published: 2026-11-24
updated: 2026-11-24
---

# Web crawling vs web scraping: the difference, with Python examples

## The 60-second version

**Web crawling finds pages. Web scraping extracts data from pages.** A crawler starts from some URLs, follows links and builds a list of pages, which is how search engines discover the web. A scraper takes a page and pulls out the parts you want: prices, article text, tables, contact details.

| | Web crawling | Web scraping |
|---|---|---|
| Goal | Discover and collect URLs or whole pages | Extract specific data from pages |
| Input | A few seed URLs | A list of known URLs, or one page |
| Output | A set of pages or a URL list | Structured data: JSON, CSV, markdown |
| Scale | Often thousands to billions of pages | Often tens to millions of pages |
| Main problems | Politeness, deduplication, URL frontier, scale | Page structure changes, JavaScript, blocking |
| Typical tools | Scrapy, crawler frameworks, search engine bots | Requests + BeautifulSoup, Playwright, extraction APIs |

**Most real projects do both:** crawl to find the pages, then scrape each page. And many AI projects need neither, because a search API already did the crawling and an extraction API does the scraping.

## What is web crawling?

**A crawler is a loop: take a URL from the queue, fetch it, find its links, add new ones to the queue, repeat.** That queue is called the frontier. A good crawler also:

- **Respects robots.txt** and crawl delays.
- **Rate-limits per domain** so it doesn't overload a site.
- **Deduplicates URLs.** The same page often lives at several addresses because of tracking parameters, trailing slashes and `http` vs `https`.
- **Stays in scope,** for example within one domain, or a path like `/docs/`.
- **Revisits pages** on a schedule to catch changes.

**A minimal same-domain crawler in Python:**

```python
import re, time, urllib.robotparser
from collections import deque
from urllib.parse import urljoin, urldefrag, urlparse
import requests

def crawl(start: str, max_pages: int = 50, delay: float = 1.0) -> list[str]:
    host = urlparse(start).netloc
    robots = urllib.robotparser.RobotFileParser(f"{urlparse(start).scheme}://{host}/robots.txt")
    robots.read()
    seen, queue, found = {start}, deque([start]), []
    while queue and len(found) < max_pages:
        url = queue.popleft()
        if not robots.can_fetch("my-crawler", url):
            continue
        r = requests.get(url, timeout=20, headers={"User-Agent": "my-crawler"})
        if "text/html" not in r.headers.get("content-type", ""):
            continue
        found.append(url)
        for href in re.findall(r'href="([^"#]+)"', r.text):
            link = urldefrag(urljoin(url, href))[0].rstrip("/")
            if urlparse(link).netloc == host and link not in seen:
                seen.add(link); queue.append(link)
        time.sleep(delay)                      # be polite: one request per second
    return found
```

For real crawls, use a framework such as Scrapy. It handles concurrency, retries, per-domain throttling and robots.txt. If the site publishes a `sitemap.xml`, read that first; it's often the whole URL list, with no crawling needed.

## What is web scraping?

**Scraping turns a page into the data you need.** The classic approach parses HTML with CSS selectors:

```python
import requests
from bs4 import BeautifulSoup

html = requests.get("https://example.com/product/123", timeout=20).text
soup = BeautifulSoup(html, "html.parser")
name  = soup.select_one("h1").get_text(strip=True)
price = soup.select_one(".price").get_text(strip=True)
```

**Where scraping gets hard:**

- **Selectors break** when the site changes its layout.
- **JavaScript-rendered pages** return an empty shell to a plain HTTP request, so you need a headless browser. See [web scraping with Playwright in Python](/blog/playwright-scraping).
- **Blocking:** rate limits, CAPTCHAs and bot detection, which is where [proxies for web scraping](/blog/proxies-for-web-scraping) come in.
- **Messy output:** for AI use, you usually want clean markdown of the main content, not raw HTML. Four of the five pages we measured came to 50,000 to 83,000 tokens of raw HTML ([our measurements](/blog/context-engineering-web-search-agents)).

## Web crawling vs web scraping: which do I need?

| You want to… | You need |
|---|---|
| Find every page on a site | Crawling (or its sitemap) |
| Monitor prices on 500 known product URLs | Scraping |
| Build a search engine or index | Crawling, then storing pages |
| Pull article text from search results for an AI agent | Scraping, or an extraction API |
| Answer questions from the live web | Neither: a search API (someone else crawled) plus extraction |
| Archive a whole docs site for RAG | Crawling, then scraping each page into markdown |

## Do AI agents need to crawl or scrape?

**Usually not directly.** An agent answering questions about the live web needs two things:

1. **Find relevant pages.** A web search API already did the crawling and indexing. One query returns the best URLs in about a second.
2. **Read them.** An extraction API fetches the page, renders JavaScript if needed, and returns clean markdown.

**Building your own crawler for that means re-creating a search engine.** It's worth it only when you need a site the search engines don't cover well, or a complete copy of specific sites.

With Keirolabs (ours), the two steps look like this:

```python
import os, requests

H = {"Authorization": f"Bearer {os.environ['KEIRO_API_KEY']}"}
hits = requests.post("https://api.keirolabs.cloud/api/v2/search/lite", headers=H,
                     json={"query": "postgres 17 release notes", "count": 5}, timeout=30).json()["results"]
page = requests.post("https://api.keirolabs.cloud/api/v2/extract", headers=H,
                     json={"url": hits[0]["url"]}, timeout=60).json()["results"][0]["content"]
```

`/search/lite` costs $0.03 to $0.10 per 1,000 searches on plans, and `/extract` costs 2 credits a page. Or use `/search/content` to get results with page text in one call.

## Is web crawling or scraping legal?

**It depends on what you collect, how, and where you are.** This isn't legal advice, but the common lines are:

- **Respect robots.txt and terms of service.**
- **Don't bypass logins** or access controls.
- **Avoid collecting personal data** without a lawful basis (GDPR, CCPA).
- **Don't republish copyrighted content wholesale.**
- **Don't overload sites.** Rate-limit, and identify your crawler.

Public, factual data collected politely is the lowest-risk case. When in doubt, ask a lawyer.

## Checklist

- **Crawl to discover pages; scrape to extract data from them.**
- **Check for a sitemap before you crawl.**
- **Respect robots.txt, rate-limit per domain, and deduplicate URLs.**
- **Use a headless browser only for JavaScript-rendered pages.**
- **Extract main content as markdown for AI use.**
- **For agents on the live web, use a search API plus extraction instead of crawling.**

New Keirolabs accounts get up to 2,000 free credits with no card ([get a key](https://platform.keirolabs.cloud/register)).
