Interactive demo

How a web crawler works

Start from one URL. Scrape it, read every link on the page, queue the ones on the same site and record the ones that point elsewhere. Repeat until the queue is empty. This demo replays a crawl over a sample site, so any domain you type gets the same example pages.

1 · queueTake next URL

The queue starts with the seed URL.

2 · scrapeFetch the page

One scrape() call returns HTML, markdown and links.

3 · extractRead every <a href>

Relative links become absolute URLs.

4 · filterQueue or record

Same site → queue. Other site → external_links.

Crawl map

drag nodes to rearrange
crawled 0/20queue 1external 0
example.com/blog/docs/pricing…/quickstart…/how-crawlers-work/signup/about/contactgithub.com/…x.com/……/markdown-for-llms…/robots-txt-explain……/2…/api…/sdkstripe.comgithub.com/…en.wikipedia.org/…developers.google.com/…/login/careerslinkedin.com/…maps.google.comcommonmark.orgrfc-editor.org/……/sitemaps-101…/crawl-budgetnpmjs.com/…pypi.org/……/backend-engineerjobs.ashbyhq.com/…

Selected: /

  • Crawled page
  • In queue
  • Scraping now
  • External link (not followed)
  • Skipped by max_depth / items_limit
Queue
Crawler log
seed https://example.com/ · max_depth 2 · items_limit 20
Each page in the crawl is one SDK call
import webcrawlerapi from "webcrawlerapi-js"

const client = new webcrawlerapi.WebcrawlerClient(process.env.WEBCRAWLER_API_KEY)

const page = await client.scrape({
  url: "https://example.com/",
  output_formats: ["markdown", "html", "links", "external_links"],
})

page.markdown     // clean markdown for your model
page.raw_content  // original HTML
page.links        // 9 internal + 2 external URLs

What just happened in the demo

A crawler started at one URL, pulled the page, found links and kept going, layer by layer, until it had mapped everything reachable from that starting point. That is the whole idea. Here is what happens under the hood.

The core loop: how a crawler thinks

The mechanics are simple: it is a loop. The hard parts come from everything around the loop, but the loop itself fits in your head.

Start with a seed URL

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

Fetch the page

The crawler sends an HTTP GET request, the 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.

Parse and extract links

The HTML is parsed to find every <a href> tag. Each href becomes a candidate URL. Internal links (same domain) go into the queue. External links are logged but skipped unless the crawl is 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. The file lists paths that are off-limits and how fast a crawler may make requests via the Crawl-delay directive. Sites watch for crawlers that ignore it and block them. A basic robots.txt looks like this:

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.

Add new URLs to the queue

A discovered URL only goes into the queue if it has not been seen before. The crawler keeps a visited set, a record of every URL already fetched or queued. This prevents infinite loops. Without it you would 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 get out of a crawl.

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 all links found on those pages, and so on. You get broad coverage fast. It is 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 go to a category page, then a product page, then a review, before coming back up. It helps when chasing a known deep path. 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 must stop early, BFS means you have already seen the pages closest to the root, which are usually the most important. With DFS you might stop having seen only one deep corner of the site.

Types of web crawlers

The architecture looks similar across crawler types, but the goals and the rules they follow differ.

Search engine crawlers (Googlebot, Bingbot)

These index the web so search engines can return relevant results. They follow robots.txt and Crawl-delay closely, because their reputation and legal standing depend on it. Google publishes the IP ranges of Googlebot so sites can verify it.

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 crawlers built to collect training data. They have become a point of friction for site owners who want to opt out.

Site audit crawlers

Tools like Screaming Frog, Ahrefs and SEMrush crawl a site to find broken links, redirect chains, missing meta tags and thin content. They usually run on demand, not continuously.

Focused and niche crawlers

Price monitoring, news aggregation and real estate listings use focused crawlers that target one site or content type and go deep rather than broad. This is where WebCrawlerAPI is commonly used: teams that need to crawl a specific site 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 production that rarely happens. Crawlers stop because a page limit was reached, a depth limit was hit, a time budget ran out, or rate limiting slowed the crawl to a halt. A crawler with no explicit stop conditions can run for days on a large site, so production crawlers always set bounds: max pages, max depth and max run time.

Web crawling vs web scraping

The terms get used interchangeably, but they differ. Crawling is discovery: following links across pages to map a site or collect URLs. Scraping is extraction: pulling specific data from a page you already found. A crawler finds pages; a scraper reads them. Most real pipelines do both.

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 do not crawl every page of every site every day. They work within a crawl budget, a limit on how many pages they fetch from your site per cycle. If your site has thousands of URLs, low-value pages such as thin content, duplicate URLs, infinite pagination and session-token URLs use up that budget before Googlebot reaches your important pages. The fix is a clean URL structure, a maintained sitemap and a robots.txt that blocks pages you do not need indexed.

The hard parts

The core loop is simple. Everything around it is not.

JavaScript rendering

Many modern sites load content with JavaScript after the initial HTML arrives. A basic HTTP crawler parses the HTML, but the content was never in it. You need a headless browser such as Puppeteer or Playwright that runs the scripts and waits for rendering to finish. See the JavaScript rendering guide.

Duplicate and infinite URLs

The same page can appear at /about, /about/, /About and /about?ref=nav. Without URL normalization all four get crawled separately. Some sites generate effectively infinite URLs: calendars that link forward forever, session tokens in every URL, pagination with no end. A production crawler has to detect and break these loops.

Rate limiting and politeness at scale

Crawl too fast and you get 429s, IP bans, or you overload a server. Respect Crawl-delay, add your own delays and back off exponentially on rate-limit responses. At scale this also means spreading requests over time.

Anti-bot measures

Cloudflare, Datadome and PerimeterX identify non-human traffic from headers, TLS handshake patterns, IP reputation and behavior. A basic crawler is blocked quickly on a well-defended site. Getting through takes rotating proxies, realistic browser fingerprints and ongoing maintenance as detection rules change.

Web crawling for AI workflows

Most of the recent growth in crawling is driven by AI use cases. LLMs need clean text at scale, and crawling is the main way to get it: teams crawl documentation sites, help centers or whole domains to build a knowledge base the model queries at runtime. Output format matters here. Raw HTML is full of navigation, ads and scripts that pollute the context window, so you want clean markdown or plain text. WebCrawlerAPI returns markdown for 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 is weeks of engineering plus ongoing maintenance. If crawling is the product you sell, build it. If it is infrastructure for something else, such as a knowledge base, a data product or an SEO tool, an API that already handles it is almost always faster and cheaper. Compare options in best web crawler APIs, or follow how to build a web crawler yourself.

Links

Internal vs external links

A link to the same site (ignoring www.) is internal. The crawler follows it. A link to another site is external. The crawler never fetches it, but with external_links on it still lists the URL in links. In the map above, internal pages are circles and external links are pink diamonds.

Filter

Which links a crawler ignores

LinkWhy
mailto:, tel:, javascript:Not pages. Nothing to fetch.
#anchorsSame page, different scroll position.
/static/, /assets/, /_next/, /cdn-cgi/Site assets, not content.
Media filesImages, video and archives are not crawled as pages.

Limits

Limits: max_depth and items_limit

Without limits a crawl of a big site never ends and costs grow with every page. max_depth stops the crawler a fixed number of clicks from the start page. items_limit stops it after a number of pages. Try max_depth 3 or items_limit 8 in the demo above and watch which pages are skipped.

Output

From crawled page to markdown for your knowledge base

Open the Markdown and HTML tabs of any crawled page in the demo. The markdown is a fraction of the HTML and keeps headings, lists and links, so it chunks cleanly for a knowledge base. See markdown cleaning for how menus and footers are removed.

Code

Run the same crawl with one request

import webcrawlerapi from "webcrawlerapi-js";

const client = new webcrawlerapi.WebcrawlerClient("YOUR_API_KEY");

const page = await client.scrape({
    url: "https://example.com/blog",
    output_formats: ["markdown", "links"],
});

console.log(page.markdown);
console.log(page.links);

More in the scrape API, crawl API docs and on the Crawl API page. The JavaScript SDK is on npm.

Web crawler FAQ

Quick answers about how crawling works

What is a web crawler?

A web crawler is a program that starts from one URL, fetches the page, reads the links on it and repeats the process for the new pages it finds. It keeps going until the queue of URLs is empty or a limit is reached.

How does a web crawler find new pages?

By reading every <a href> on each page it fetches. Relative links become absolute URLs, and links to the same site that were not seen before are added to the queue.

What is the difference between crawling and scraping?

Scraping fetches one URL you name and returns its content. Crawling discovers pages on its own from a seed URL and scrapes many of them. In WebCrawlerAPI, scrape is /v2/scrape and crawl is /v1/crawl.

Does a crawler follow external links?

No. Links to other sites are recorded but never fetched. With external_links enabled on a scrape request, they are returned in the links list so you can see where a page points.

Which links does a crawler skip?

mailto: and tel: links, same-page #anchors, javascript: links, static files such as /static/ or /assets/ paths and media files. These are not pages, so there is nothing to crawl.

What do max_depth and items_limit do?

max_depth limits how many clicks away from the start page the crawler goes. items_limit stops the crawl after that many pages. Both keep cost and crawl time under control.

Does the crawler respect robots.txt?

Only if you set respect_robots_txt to true. The default is false. Per-site concurrency is shared and capped, so a crawl will not hammer the target website.

How does a web crawler know when to stop?

In theory when the queue is empty. In practice production crawlers set explicit limits: a maximum number of pages, a maximum depth or a maximum run time. Without them a crawl of a large site can run for days.

What is BFS in web crawling?

BFS (breadth-first search) visits all pages at the current depth before going deeper. It gives broad coverage fast and means the pages closest to the start page are seen first if a crawl stops early. It is the default for most crawlers.

What is crawl budget?

Crawl budget is the number of pages a search engine crawler fetches from your site in a crawl cycle. Duplicate and low-value URLs use it up, so a clean URL structure, a maintained sitemap and a tuned robots.txt help the right pages get crawled.

Why convert crawled pages to markdown?

Markdown keeps headings, lists and links and drops the markup, so it takes fewer tokens and chunks cleanly. That makes it a good input for a knowledge base or support bot.

Crawl a real website

No credit card to try. Failed pages are free.