Web Crawler
Fetching the web.
A search engine starts with a web crawler. It downloads pages, finds links in them, and follows those links to more pages. Billions of times.

- Download a page
- Find its links
- Follow them, billions of times
The crawl loop
The crawler starts from a list of seed URLs, in a queue called the frontier. It takes a URL, downloads the page, and stores it. It extracts every link. Links it hasn't seen before go back into the frontier. And the loop continues.
- Frontier
- Download
- Store page
- Extract links
- New? Add to frontier

A tiny crawler
Here's the loop on a tiny pretend web of five pages. A set remembers every URL we've seen, so we never fetch a page twice, even though pages link back to each other. Run it. Each page is crawled exactly once, in breadth first order.
from collections import deque
web = {
"/": ["/shop", "/about"],
"/shop": ["/shop/mugs", "/"],
"/about": ["/"],
"/shop/mugs": ["/shop", "/shop/pots"],
"/shop/pots": ["/shop/mugs"],
}
frontier, seen = deque(["/"]), {"/"}
while frontier:
url = frontier.popleft()
print("crawl", url)
for link in web[url]:
if link not in seen:
seen.add(link)
frontier.append(link)crawl / crawl /shop crawl /about crawl /shop/mugs crawl /shop/pots
Summary
A crawler takes URLs from a frontier, downloads pages, extracts links, and adds new ones back, remembering what it's seen. Next, crawling the real web at scale.
Key takeaways- Frontier queue
- Seen set
- Download, extract, repeat