A web crawler starts from seed URLs and repeats one loop: take a URL from the frontier, fetch the page, parse its text and links, and add each new, permitted link to the frontier. Run first in, first out, the loop is a breadth-first search, which reaches well-linked pages early. It finds only pages that some chain of links connects to its seeds. The web graph is a bow-tie, and in a 1999 crawl of 203 million pages a crawl seeded in the core could reach about 100 million and never the rest. Spider traps make the frontier endless, so a crawl stops on a budget. Limits such as a per-host quota stop traps at the cost of real pages. Every crawler must be robust and polite.
Six ordinary pages sit on two hosts, a university at uni.edu and a library at lib.org. A third host, cal.org, serves a calendar whose page for each month links to the next month. A program is given one address, the university's home page, and nothing else. Which pages can it find by following links, in what order should it visit them, and how does it know when to stop? In brief: it can find exactly the pages that some chain of links connects to its starting address, first in, first out is the baseline order, and on this web it never learns that it is done, so it stops on a budget. The sections below work out each answer.
A program that does this work is a web crawler, also called a spider or robot. It finds and downloads web pages automatically by following the links between them. For a search engine, it is the first stage of the pipeline described in search engine architecture. The crawler gathers pages, the indexer builds an inverted index from them, and the query processor searches that index. A search engine can only return pages its crawler has fetched, and only in the form in which it last fetched them. Manning, Raghavan, and Schütze (2008, §20.1) state the goal as gathering as many useful pages as possible, quickly and efficiently, together with the link structure that connects them.
Here is the route. First we look at what a link names: the parts of a URL. Then we run the crawl loop by hand on the toy web, where the calendar turns out to be a trap. Next come the features every crawler must have and those it should have. Then we look at the shape of the web's link graph, which decides what a crawl from given seeds can reach, and at what no crawl of links can reach. Worked problems close the article. Later articles in this topic build on the loop set out here.
URLs
Before a crawler can follow a link, it has to know what the link names. Every page is identified by a Uniform Resource Locator. A URL such as
https://www.example.edu/graduate/courses.html?term=fall#csc790
has five parts:
- a scheme (
https), which names the protocol; - a host (
www.example.edu), which names the server; - a path (
/graduate/courses.html), which names the resource on that server; - an optional query (
term=fall), which passes parameters to a program on the server; - an optional fragment (
csc790), which points to a place within the page and is never sent to the server.
To fetch the page, the crawler resolves the host to an IP address through the Domain Name System. It then connects to that server and requests the path and query with HTTP.
Many different URLs can name the same page. The host is case-insensitive, and the default port can be written or omitted. Relative links must be resolved against the page they appear on, and the fragment changes nothing. Reducing URLs to one canonical form, called URL normalization, is described in crawler architecture.
Example (a changed fragment and a changed query). To a crawler, the URL above and the same URL ending in #top instead of #csc790 name one page, while the same URL with ?term=spring in place of ?term=fall may name a different page. The fragment is never sent to the server, so the first two URLs produce the same request. The second pair may be two pages. The query goes to the server, which can return different content for each term, so a crawler has to treat them as different URLs unless it knows how the site behaves.
The crawl loop
With URLs in hand, the crawler's work is a loop. The basic operation is the same for any crawler (Manning, Raghavan, and Schütze, 2008, §20.2):
- Start from seeds. The crawl begins with a set of seed URLs, typically well-known, well-connected pages.
- Choose a URL. The crawler takes a URL from the URL frontier, its list of URLs discovered but not yet fetched.
- Fetch. It downloads the page over HTTP, following redirects and handling errors.
- Parse. It extracts the page's text, for the indexer, and its links.
- Add new URLs. Each extracted link is normalized, checked against the URLs already seen, filtered by rules such as robots.txt, and, if it passes, added to the frontier.
- Repeat until the frontier is empty or until the crawl's budget runs out.
It is natural to picture a crawl ending when the frontier is empty and the web has been copied. On the web that never happens, if only because some sites generate pages without limit, so a real crawl stops on a budget.
If the frontier is a first-in, first-out queue, the crawl is a breadth-first traversal of the web graph from the seeds. Breadth-first order has a useful property beyond simplicity. Important pages tend to have many incoming links, so they are reached early from many directions. Najork and Wiener (2001) found, on a crawl of 328 million pages, that breadth-first crawling discovered pages with high PageRank early. Production crawlers replace the simple queue with a prioritized frontier, but breadth-first order is a sound baseline.
A small crawl, step by step
Back to the toy web. The loop fits in a few lines. Leaving out fetching and parsing, which crawler architecture covers, the bookkeeping is a queue of URLs to fetch and a set of URLs already seen:
frontier = deque([seed]) # URLs discovered but not yet fetched, first in, first out
seen = {seed} # every URL ever added to the frontier
while frontier:
url = frontier.popleft()
for link in links_on(url): # fetch and parse
if link not in seen and allowed(link):
seen.add(link)
frontier.append(link)
A URL is marked as seen when it is added to the frontier, not when it is fetched. A page linked from many places therefore enters the queue only once.
In the toy web, the university's news page links to the calendar, and the calendar has no last page. The crawler starts from uni.edu/. As a defense against traps like the calendar, described under robustness below, it admits at most 4 URLs per host to the frontier. In the table, "added" lists the links that entered the frontier; links to URLs already seen are not listed.
| Step | Fetched (depth) | Added to the frontier | Frontier afterward |
|---|---|---|---|
| 1 | uni.edu/ (0) |
uni.edu/courses, uni.edu/news, lib.org/ |
courses, news, lib.org/ |
| 2 | uni.edu/courses (1) |
uni.edu/csc790 |
news, lib.org/, csc790 |
| 3 | uni.edu/news (1) |
cal.org/?m=1 |
lib.org/, csc790, m=1 |
| 4 | lib.org/ (1) |
lib.org/catalog |
csc790, m=1, catalog |
| 5 | uni.edu/csc790 (2) |
none (its one link, to the catalog, is already seen) | m=1, catalog |
| 6 | cal.org/?m=1 (2) |
cal.org/?m=2 |
catalog, m=2 |
| 7 | lib.org/catalog (2) |
none | m=2 |
| 8 | cal.org/?m=2 (3) |
cal.org/?m=3 |
m=3 |
| 9 | cal.org/?m=3 (4) |
cal.org/?m=4 |
m=4 |
| 10 | cal.org/?m=4 (5) |
none: cal.org/?m=5 refused, host limit reached |
empty |
The trace shows two things at once. Breadth-first order finished every page at depth 1 before any at depth 2, so the six pages of real content were all fetched within the first seven steps. The calendar, by contrast, contributed a new page at every level. Without the limit the crawl would never end: run without it, the same crawl is still descending the calendar after 12 steps, at depth 7.
The limit stopped the trap, so a stricter limit might seem safer still. It is not.
Example (a quota of three). If the crawler admits at most 3 URLs per host instead of 4, the calendar is still cut off, but a real page is lost with it: uni.edu/csc790. The university's home, courses and news pages use up uni.edu's quota of three, so the link to csc790 in step 2 is refused. The crawl ends after 8 fetches, with the calendar stopped at cal.org/?m=3. The limit is blunt. Every defense against traps is a trade between the pages it saves fetching and the pages it misses. The traces for all three settings are computed by tools/experiments/crawling/crawl_trace.py in the site repository.
Features a crawler must provide
The calendar is one case of a general hazard. Manning, Raghavan, and Schütze (2008, §20.1.1) name two features that any crawler on the open web must have.
Robustness
The web contains spider traps: parts of sites that generate an unbounded number of distinct URLs. They take several forms:
- A calendar with a "next month" link on every page has no last page.
- A site that puts a session identifier in every URL makes each visit's links look new.
- A misconfigured server may return the same page, with the same relative links, for any path under a directory. It can then be crawled at
/a/,/a/a/,/a/a/a/, and so on.
Some traps are deliberate. Spammers build them to fill a search engine's index with their pages, in the hope of appearing high in its results or of adding links that bias link-based ranking (Olston and Najork, 2010, §6.2).
A crawler has no general way to tell that a site is infinite. It defends itself instead with limits and checks, of which the toy crawler's host quota is only the first:
- limits on the number of pages fetched from each host, and on the depth of paths and length of URLs;
- duplicate detection, so that pages whose content has been seen before are not mined for more links;
- URL normalization, so that trivially different URLs are recognized as one;
- timeouts and size limits on every fetch, so that one slow or enormous response cannot stall the crawler.
Robustness also means surviving the ordinary mess of the web. Pages arrive with malformed HTML and wrong character encodings, servers time out, and responses claim one content type and contain another. From bytes to documents describes what can go wrong in turning such responses into text.
Politeness
Robustness protects the crawler from the web. Politeness protects the web from the crawler. Every request consumes the server's bandwidth and processing time. A crawler fetching from one server as fast as its connection allows can degrade that server for its human users, and to the server's operator it looks like an attack. Servers have explicit policies, published in a file called robots.txt. They also have implicit ones, such as not sending many requests at once. A crawler must respect both. Politeness and robots.txt describes how.
Features a crawler should provide
A crawler with only the two essentials would be safe, but not necessarily useful. Beyond them, a crawler serving a search engine should have several further qualities (Manning, Raghavan, and Schütze, 2008, §20.1.2):
- Quality. Much of the web is spam, duplicates, or of little use. The crawler should be biased toward useful pages, fetching them first and revisiting them more often.
- Scalability. Adding machines or bandwidth should increase the crawl rate roughly in proportion.
- Performance and efficiency. The crawler should make good use of processors, storage, and network bandwidth. A machine waiting on a slow server should be fetching from others in the meantime.
- Distributed operation. A crawl of the web is too large to finish quickly on one machine, so the crawler should be able to run on many machines, possibly in several locations, as described in distributed crawling.
- Freshness. Pages change and disappear. The crawler should run continuously and revisit each page at a rate suited to how often it changes, a problem treated in freshness and recrawling.
- Extensibility. New formats, protocols, and kinds of content keep appearing. A modular design lets one part of the crawler change without rebuilding the rest.
The shape of the web graph
The toy crawl reached every page because every page could be reached from the seed. Whether that holds on the real web depends on the shape of its link graph. The web graph has one node for each page and one directed edge for each link. The links into a page are its in-links and their number is its in-degree; the links out of it are its out-links, and their number its out-degree. Two measured properties of this graph matter to a crawler (Manning, Raghavan, and Schütze, 2008, §19.2.1).
The graph is not strongly connected. A directed graph is strongly connected when every node can reach every other along directed edges. Broder and colleagues (2000) tested this on a crawl of about 203 million pages and 1,466 million links made by the AltaVista search engine in May 1999. They found the structure now called the bow-tie:
- a strongly connected core (SCC) of about 56 million pages, 28 percent of the crawl, in which every page can reach every other;
- a set IN of about 43 million pages that can reach the core but cannot be reached from it, such as new pages that nothing in the core links to yet;
- a set OUT of about 43 million pages that can be reached from the core but do not lead back to it, such as sites whose links are all internal;
- about 44 million pages in tendrils, which hang off IN or OUT without passing through the core, and a remainder in small pieces not connected to the rest at all.
The consequences for a crawl follow from the definitions. A crawl seeded inside the core reaches the core and OUT, about 100 million of the 203 million pages, and nothing in IN or the tendrils, however long it runs. Pages in IN are found only if a seed lies in IN or upstream of it, which is why crawlers accept submitted URLs and sitemaps as extra seeds. Broder and colleagues observed exactly this split. A breadth-first search from a randomly chosen page either died out after a small number of pages or went on to cover about 100 million. For a random pair of pages, a directed path from the first to the second existed only 24 percent of the time.
Example (the bow-tie of the toy web). The toy web has a core, an OUT set and no IN set. The university's home, courses and news pages, the library's home page and every calendar page can all reach one another, because each calendar page links back to the news page. They form the core. The pages uni.edu/csc790 and lib.org/catalog are in OUT: the core reaches them, and from them the only link leads from csc790 to the catalog, which has no links at all. With the calendar cut at its fourth month the graph has 10 pages. The 8 core pages each reach all 9 others, csc790 reaches 1 page and the catalog reaches none, so $8 \times 9 + 1 = 73$ of the $10 \times 9 = 90$ ordered pairs of distinct pages are joined by a path. A crawl seeded at the catalog fetches one page and stops.
Degrees follow a power law. If each page chose the targets of its links at random, in-degrees would follow a Poisson distribution, bunched around their mean. They do not. The number of pages with in-degree $i$ is close to proportional to $1/i^{\gamma}$, a power law, and Broder and colleagues measured $\gamma \approx 2.1$ for in-degree, in agreement with earlier studies, and $2.72$ for out-degree. Under such a law most pages have very few in-links and a small number have enormously many. The worked problems below compute what the exponent 2.1 implies. The skew fits the observation above that breadth-first order reaches heavily linked pages early: a page linked from very many places has a link on some page the crawl fetches soon.
What a crawler cannot reach
Even a robust, polite crawler with unlimited time would not fetch the whole web. Following links reaches only pages that some other reachable page links to, which leaves out IN and the tendrils when the seeds lie in the core. Three further kinds of content have no links leading to them at all, or none that a plain request can follow:
- pages behind logins;
- pages generated in response to form submissions;
- content that appears only after a script runs in the browser.
Together they make up the deep web, which Bergman (2001) estimated to be hundreds of times larger than the part search engines index.
Example (a page nothing links to). When this site was crawled for crawler architecture, it had 77 wiki articles, each linked from a topic page or from another article. The site also had a wiki index page at /wiki/, which no page linked to. The crawler found every one of the 77 articles, and it did not find the index page. A page that exists but is not linked is invisible to a crawler, unless the site lists it in a sitemap or someone submits it directly.
Worked problems
Problem 1 is posed on the toy web of this article. Problems 2 to 4 are Exercises 19.1 to 19.4 and 21.1 of the course text (Manning, Raghavan, and Schütze, 2008), restated in our words. Each is solved from the definitions above, and the numbers are checked in crawl_trace.py.
Problem 1 (a different seed). Run the toy crawl again, breadth-first with at most 4 URLs per host, from the seed lib.org/ instead of uni.edu/. Give the trace, and say what changes.
The library's home page links to its catalog and to the university's home page, so both enter the frontier at depth 1. The rest follows the loop, one fetch per row. As before, links to URLs already seen are not listed.
| Step | Fetched (depth) | Added to the frontier |
|---|---|---|
| 1 | lib.org/ (0) |
lib.org/catalog, uni.edu/ |
| 2 | lib.org/catalog (1) |
none (it has no links) |
| 3 | uni.edu/ (1) |
uni.edu/courses, uni.edu/news |
| 4 | uni.edu/courses (2) |
uni.edu/csc790 |
| 5 | uni.edu/news (2) |
cal.org/?m=1 |
| 6 | uni.edu/csc790 (3) |
none (the catalog is already seen) |
| 7 | cal.org/?m=1 (3) |
cal.org/?m=2 |
| 8 | cal.org/?m=2 (4) |
cal.org/?m=3 |
| 9 | cal.org/?m=3 (5) |
cal.org/?m=4 |
| 10 | cal.org/?m=4 (6) |
none: cal.org/?m=5 refused, host limit reached |
The crawl again makes 10 fetches and reaches the same 10 pages, because the library's home page lies in the core of the toy web and the core reaches everything. What changes is the order and the depths. The six real pages are now all fetched within the first six steps, one step sooner than from the university, since the catalog comes early. Every university page is one level deeper than before, and the calendar ends at depth 6 where it ended at depth 5. Depth measures distance from the seed, so it is a property of the crawl and not of the page.
Problem 2 (Exercises 19.1 and 19.2). Suppose the number of pages with in-degree $i$ is proportional to $1/i^{2.1}$ for $i = 1, 2, 3, \dots$ What is the probability that a randomly chosen page has in-degree 1, and what is the average in-degree?
The probabilities must sum to 1. Writing $P(i) = c / i^{2.1}$,
$$1 = \sum_{i=1}^{\infty} \frac{c}{i^{2.1}} = c\,\zeta(2.1), \qquad \zeta(s) = \sum_{i=1}^{\infty} \frac{1}{i^{s}},$$
where $\zeta$ is the Riemann zeta function, the name for this sum. It has no closed form at 2.1. Summing the series numerically gives $\zeta(2.1) = 1.5602$, so $c = 1/1.5602 = 0.641$. That is the answer to the first question: $P(1) = c/1^{2.1} = 0.641$. Almost two pages in three have a single in-link. The next value is $P(2) = 0.641 / 2^{2.1} = 0.641/4.287 = 0.150$.
The average in-degree is
$$\sum_{i=1}^{\infty} i \cdot \frac{c}{i^{2.1}} = c \sum_{i=1}^{\infty} \frac{1}{i^{1.1}} = \frac{\zeta(1.1)}{\zeta(2.1)} = \frac{10.5844}{1.5602} = 6.78.$$
The mean is more than six times the most common value. The series for $\zeta(1.1)$ converges very slowly, because the rare pages with large in-degree carry a large share of the links: under this law the pages with more than 100 in-links, about 0.4 percent of all pages, receive 60 percent of the links. The model leaves out pages with no in-links at all, for which $1/i^{2.1}$ is undefined, so it describes pages that have at least one.
Problem 3 (Exercise 19.3). With the same law, what happens to the fraction of pages with in-degree $i$ as the largest in-degree in the graph grows without bound? How does the answer depend on the exponent?
If the largest in-degree is $M$, the normalizing sum stops at $M$, and the fraction of pages with in-degree $i \le M$ is
$$P_M(i) = \frac{1/i^{2.1}}{\sum_{j=1}^{M} 1/j^{2.1}}.$$
The denominator grows with $M$, so every fraction diminishes as $M$ grows. It does not diminish to zero: the denominator converges to $\zeta(2.1)$, so $P_M(i)$ falls to the limit $1/(i^{2.1}\,\zeta(2.1))$ of Problem 2. For in-degree 1 the fraction is 1 when $M = 1$, then $0.811$ for $M = 2$, $0.670$ for $M = 10$, $0.643$ for $M = 100$ and $0.641$ for $M = 10{,}000$.
The same holds for every exponent above 1, since $\sum 1/j^{s}$ converges exactly when $s > 1$. For an exponent of 1 or less the sum grows without bound, so every fraction diminishes to zero and no limiting distribution exists.
Problem 4 (Exercises 19.4 and 21.1). (a) The average in-degree of the pages in a snapshot of the web graph is 9. What is the average out-degree? (b) Is it always possible to follow links from any page of the web graph to any other?
(a) It is also 9, provided both ends of every counted link lie in the snapshot. Each link is one out-link of the page it leaves and one in-link of the page it enters. Summing in-degrees over all pages counts every link once, and so does summing out-degrees. The two sums are equal, and dividing each by the same number of pages gives equal averages. The distributions still differ: Broder and colleagues measured different exponents for the two.
(b) No. The web graph is not strongly connected. In the bow-tie, no page of the core can reach a page of IN, and no page of OUT can reach the core, and Broder and colleagues found a directed path between only 24 percent of random pairs. The toy web shows it on a small scale: no link leaves lib.org/catalog, so no other page can be reached from it.
What we have learned
A crawler is a loop over a frontier, and run first in, first out it is a breadth-first search that reaches well-linked pages early. On the toy web it fetched all six real pages in seven steps and would have descended the calendar forever without a limit, yet a quota of three cost a real page. The web graph is a bow-tie, so what a crawl reaches depends on where its seeds lie. A crawler must also be polite, and it can never reach pages that nothing links to.
The toy crawler fetched as fast as it liked. Politeness and robots.txt establishes how fast a real one may fetch from one server, and how a site says which pages may be fetched at all.
References
- Bergman, M. K. (2001). The deep web: Surfacing hidden value. Journal of Electronic Publishing, 7(1). record · 2 pages
- Broder, A., Kumar, R., Maghoul, F., Raghavan, P., Rajagopalan, S., Stata, R., Tomkins, A., and Wiener, J. (2000). Graph structure in the web. Computer Networks, 33(1–6), 309–320. record
- Manning, C. D., Raghavan, P., and Schütze, H. (2008). Introduction to Information Retrieval, sections 19.2, 20.1–20.2 and 21.1. Cambridge University Press. record · 102 pages
- Najork, M., and Wiener, J. L. (2001). Breadth-first search crawling yields high-quality pages. In Proceedings of the Tenth International World Wide Web Conference (WWW10), 114–118. record · 2 pages
- Olston, C., and Najork, M. (2010). Web crawling. Foundations and Trends in Information Retrieval, 4(3), 175–246. record · 3 pages
Reviewed: verified, 16 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 23 Nov 2026 · 9 revisions