How a Web Crawler Works

A visual, step-by-step explanation of how web crawlers work — from the seed URL through BFS traversal, queue management, and link discovery.

Written byAndrii
Published on
How a Web Crawler Works

What Just Happened

You just watched a crawler work through a site. It started at one URL, pulled the page, found links, and kept going — layer by layer — until it mapped everything reachable from that starting point. That's the whole idea. Here's what was actually happening under the hood.

The Core Loop: How a Crawler Thinks

The mechanics are simple. It's a loop. The hard parts come from everything around that loop — but the loop itself you can hold in your head.

Core crawler loop

Start with a seed URL

A crawl starts with one URL. That URL goes into a queue. Everything that follows is a consequence of what's on that first page.

Fetch the page

The crawler sends an HTTP GET request — same as your browser when you type an address. The server sends back HTML. If the server blocks the request or returns an error, the crawler logs it and moves on.

The HTML gets parsed to find every <a href="..."> tag. Each href becomes a candidate URL. Internal links — same domain, same origin — go into the queue. External links get logged but skipped unless the crawl is explicitly configured to follow them.

Respect robots.txt and crawl delays

This step is not optional if you want to crawl responsibly. Before fetching pages from a domain, a real crawler checks the site's robots.txt file. This file tells crawlers which paths are off-limits and how fast they can make requests via the Crawl-delay directive. Ignoring it is bad practice — sites monitor for this, and they will block crawlers that don't comply. Here's what a basic robots.txt looks like:

User-agent: *
Disallow: /admin/
Disallow: /private/
Crawl-delay: 2

User-agent: Googlebot
Allow: /

The Disallow lines mark paths the crawler must skip. Crawl-delay: 2 means wait two seconds between requests. Ignore these and you're not just impolite — you're getting your IP banned.

Add new URLs to the queue

Newly discovered URLs only go into the queue if they haven't been seen before. The crawler keeps a visited set — a record of every URL it has already fetched or queued. This is what prevents infinite loops. Without it, you'd circle the same pages forever.

Repeat

The loop runs until the queue is empty. At that point, every page reachable from the seed URL — within whatever limits were set — has been visited.

Traversal Strategy: BFS vs DFS

The queue controls the order pages are visited. That order is the traversal strategy, and it changes what you actually get out of a crawl.

BFS vs DFS traversal

Breadth-first search (BFS)

BFS visits all pages at the current depth before going deeper. Start at the homepage, follow all links on that page, then follow all links found on those pages, and so on. You get broad coverage fast. It's the default for most general-purpose crawlers.

Depth-first search (DFS)

DFS follows one branch as deep as it goes before backtracking. From the homepage it might follow one link to a category page, then one link to a product page, then one link to a review — before coming back up. Useful in some specific cases, like chasing a known deep path through a site. The risk is spending all your time in one corner while the rest of the site sits untouched.

Why most crawlers choose BFS

If you hit a rate limit or have to stop a crawl early, BFS means you've already seen the most important pages — the ones closest to the root. With DFS, you might stop mid-crawl having only seen one deep corner while the homepage's other sections were never reached. That's a bad trade.

Types of Web Crawlers

Not all crawlers are doing the same thing. The architecture looks similar across types, but the goals — and the rules they follow — differ a lot.

Search engine crawlers (Googlebot, Bingbot)

These crawlers index the web so search engines can return relevant results. They follow robots.txt and Crawl-delay carefully — their reputation and legal standing depend on it. Googlebot is identified by its user-agent string, and Google publishes its IP ranges so sites can verify it's legitimate.

AI training crawlers (Common Crawl, GPTBot)

Common Crawl is an open dataset used to train many large language models. OpenAI's GPTBot and Anthropic's ClaudeBot are more recent examples — crawlers built specifically to collect training data for AI. These have become a point of friction for site owners who want to opt out of having their content used for model training.

Site audit crawlers

Tools like Screaming Frog, Ahrefs, and SEMrush run crawlers to audit site health — finding broken links, redirect chains, missing meta tags, thin content. Typically run on-demand, not continuously.

Focused and niche crawlers

Price monitoring, news aggregation, real estate listings — focused crawlers target one site or one content type and go deep rather than broad. This is the category where WebCrawlerAPI is commonly used: teams that need to crawl a specific site or set of sites repeatedly as part of a data pipeline or AI workflow.

When Does a Crawler Stop?

The obvious answer is: when the queue is empty. In practice, that rarely happens in production. Crawlers stop because a page limit was reached, a depth limit was hit, a time budget ran out, or rate limiting kicked in and slowed the crawl to a halt.

A crawler with no explicit stop conditions can run for days or weeks on a large site. Production crawlers always set bounds — max pages, max depth, max run time — so the crawl is predictable and infrastructure costs are controlled.

Web Crawling vs Web Scraping

These terms get used interchangeably, but they mean different things. Crawling is about discovery — following links across pages to map a site or collect URLs. Scraping is about extraction — pulling specific data from a page you've already found. A crawler finds pages; a scraper reads them.

Most real pipelines do both: crawl to discover which pages exist, then scrape each one to extract the content you actually need.

Web CrawlingWeb Scraping
GoalDiscover pagesExtract data
InputSeed URLKnown page URL
OutputList of URLs / pagesStructured data fields
ScopeSite-widePage-level

SEO and Crawl Budget: Why This Matters for Your Site

Search engine crawlers don't crawl every page on every site every day. They work within a crawl budget — a limit on how many pages they'll fetch from your site per cycle. If your site has thousands of URLs, low-value pages like thin content, duplicate URLs, infinite pagination, or session-token URLs eat up that budget before Googlebot ever reaches your important pages.

Fix: clean URL structure, a maintained sitemap, and a robots.txt that blocks pages you don't need indexed. Unglamorous, but it's what moves the needle.

The Hard Parts

The core loop is simple. Everything around it isn't.

Production crawler hard parts

JavaScript rendering

Many modern sites load content via JavaScript after the initial HTML is delivered. A basic HTTP crawler fetches the HTML and parses it — but the actual content was never in the HTML to begin with; it was injected by a script. To handle this, you need a headless browser — Puppeteer or Playwright — that actually runs the JavaScript and waits for the page to finish rendering before extracting anything.

Duplicate and infinite URLs

The same page can appear at /about, /about/, /About, and /about?ref=nav. Without URL normalization, those four URLs all get crawled separately. Worse, some sites generate effectively infinite URLs — calendar pages that link forward forever, session tokens embedded in every URL, paginated query strings with no defined end. A production crawler needs to detect and break these loops explicitly.

Rate limiting and politeness at scale

Crawl too fast and you get 429s, IP bans, or you hammer a server that can't handle the load. Respect Crawl-delay from robots.txt, add your own delays, and back off with exponential waits when you see rate limit responses. At scale, this also means spreading requests over time rather than firing them all at once.

Anti-bot measures

Cloudflare, Datadome, PerimeterX — these systems identify non-human traffic by fingerprinting headers, TLS handshake patterns, IP reputation, and behavioral signals. A basic crawler gets blocked almost immediately on any well-defended site. Getting through requires rotating proxies, realistic browser fingerprints, and ongoing maintenance as detection rules update. You fix it, they update. You fix it again. This is the part of crawling infrastructure that never stays solved — it just stays managed.

Web Crawling for AI and LLM Workflows

Most of the recent growth in crawling infrastructure is driven by AI use cases. LLMs need clean text at scale, and web crawling is the main way to get it. RAG pipelines crawl documentation sites, knowledge bases, or entire domains to build retrieval indexes the model queries at runtime.

The difference from traditional crawling is that output format matters a lot here. Raw HTML is noisy — nav elements, ads, scripts, and boilerplate that pollute the context window. You want clean Markdown or plain text. WebCrawlerAPI returns Markdown by default for exactly this reason.

Build vs Buy: When to Use a Crawler API

Building a basic crawler takes an afternoon. Building one that handles JavaScript rendering, anti-bot defenses, retries, deduplication, proxy rotation, robots.txt compliance, and stable output formatting — that's weeks of engineering, plus ongoing maintenance as sites update their defenses.

The question isn't whether you can build it. It's whether building and maintaining it is the best use of your time. If crawling is the core product you're selling, build it. If crawling is infrastructure for something else — a RAG pipeline, a data product, an SEO tool — an API that already handles all of this is almost always the faster and cheaper path.

What WebCrawlerAPI Does

WebCrawlerAPI runs the full loop — seed URL, BFS traversal, JavaScript rendering, deduplication, anti-bot handling, retries, robots.txt compliance — and returns clean content in HTML, Markdown, or plain text. You call one endpoint with a URL and your options. It handles the rest.

Teams use it when crawling needs to work reliably and they don't want to own the infrastructure to make that happen.

FAQ

How does a web crawler work?

A web crawler starts with a seed URL, fetches the page, parses the HTML to find links, adds new URLs to a queue, and repeats. It keeps a visited set of every URL already seen to avoid loops. The crawl continues until the queue is empty or a limit — page count, depth, or time — is reached.

What is the difference between web crawling and web scraping?

Crawling is about discovery — following links to find pages. Scraping is about extraction — pulling specific data from a page you've already found. A crawler maps a site; a scraper reads it. Most real-world data pipelines combine both: crawl to find pages, scrape to extract content from each one.

How does a web crawler know when to stop?

In theory, a crawler stops when the queue is empty — every reachable page has been visited. In practice, production crawlers always set explicit limits: a maximum number of pages, a maximum depth, or a maximum run time. Without those limits, a crawl on a large site can run indefinitely.

What is BFS in web crawling?

BFS stands for Breadth-First Search. The crawler visits all pages at the current depth before going deeper. Start at the homepage, fetch all linked pages, then fetch all pages linked from those, and so on. BFS gives broad, representative coverage quickly and is the default traversal strategy for most crawlers.

What is robots.txt and why do crawlers follow it?

robots.txt is a text file at the root of a domain that tells crawlers which paths to skip and how fast to crawl. It's a convention, not technically enforced — but well-behaved crawlers follow it because ignoring it gets IPs blocked and damages the crawler operator's reputation. Search engines follow it strictly because their business depends on being allowed access to sites.

What is crawl budget?

Crawl budget is the number of pages a search engine crawler will fetch from your site within a given crawl cycle. It's not unlimited. If your site has many low-value or duplicate URLs, they consume crawl budget that would otherwise go to your important pages. A clean URL structure, a good sitemap, and a well-configured robots.txt help make sure the right pages get crawled and indexed.


About the Author

Andrii Mazurian
Andrew Mazurian@andriixzvf

Founder, WebCrawlerAPI · 🇳🇱 Netherlands

Engineer with 15 years of experience in APIs, big data, and infrastructure. Founded WebCrawlerAPI in 2024 with a single goal: to build the best data API, and have been shipping it every day since.