TL;DR
A web crawler works by starting from one or more seed URLs, downloading each page, extracting the links it finds, and adding new links to a queue to visit next. It repeats this loop, tracking already-visited URLs to avoid duplicates, until it runs out of links or hits a limit you set.
The Core Loop
Every crawler, from a 20-line script to a search engine, runs the same cycle:
- Seed. Begin with one or more seed URLs.
- Fetch. Download the page at the front of the queue.
- Parse. Extract the content you want and the links on the page.
- Filter and enqueue. Keep links that are in scope and not yet seen, and add them to the queue (the URL frontier).
- Repeat until the queue is empty or a limit is reached.
A minimal version makes the loop concrete:
from collections import deque
def crawl(seed, same_host, max_pages=500):
queue, seen, results = deque([seed]), {seed}, []
while queue and len(results) < max_pages:
url = queue.popleft()
html = fetch(url) # your fetch + retry logic
results.append((url, html))
for link in extract_links(html): # absolute, in-scope links
if link not in seen and same_host(link):
seen.add(link)
queue.append(link)
return resultsWhat Separates Toy Crawlers From Real Ones
The loop is simple; running it at scale is not. Production crawlers add:
- Politeness. Respecting robots.txt and crawl delay so they do not overload a site. See polite crawling.
- Scope control. A defined crawl scope and depth so the crawl does not wander the whole internet.
- Deduplication. URL normalization and a seen-set so the same page is not fetched repeatedly.
- Ordering. Breadth-first or depth-first traversal depending on the goal.
- Resilience. Retries, timeouts, and handling for blocks and errors.
Crawling vs Scraping
Crawling is discovery: finding and traversing URLs. Scraping is extraction: pulling structured data out of a page. Most real jobs do both, and the distinction is covered in crawling vs scraping.
Key Takeaways
- A crawler loops over fetch, parse, enqueue, tracking seen URLs to avoid loops.
- The loop is trivial; politeness, scope, dedup, and resilience make it production-ready.
- Crawling finds pages; scraping extracts data from them.
How ScrapeGraphAI Handles This
ScrapeGraphAI's crawl endpoint runs the full loop for you, with managed politeness, scope and depth controls, deduplication, and per-page extraction, so you describe what to collect instead of building the traversal machinery.