Sub topic 1
How Search Engines Find Pages Through Links
Prerequisites
This chapter assumes you have:
- Basic HTML, including the
aelement and itshrefattribute. - A working idea of how a browser requests a page over HTTP, including status codes such as 200, 301, and 404.
- General awareness of what SEO is and why pages need to be found in search.
You don't need to know how ranking works. This chapter covers only how pages are discovered, which comes before ranking.
Why discovery comes first
A page can't appear in search results until the search engine knows the page exists. Most of the later chapters, on slugs, internal links, and anchor text, matter because of how that discovery works. Slugs name the pages that crawlers find. Internal links are the paths crawlers use to find them. Anchor text is the description the crawler reads along the way.
This chapter builds the working model. It also lists the errors that cause pages to be missed.
The pipeline: discover, crawl, render, index
A search engine processes a URL in stages. The names vary by engine, but the shape is the same.
- Discovery is learning that a URL exists. A URL is a full web address, such as
https://example.com/blog/. - Crawling is fetching the URL with a bot. Google's bot is called Googlebot.
- Rendering is running the page's JavaScript to see the final content. Rendering can happen later than the first fetch.
- Indexing is storing what the engine learned, so the page can be returned for searches.
The dotted arrows are the important part. Each fetched page is a source of new URLs, so crawling feeds itself. The engine fetches a page, extracts its links, and adds the new URLs to a queue of pages to fetch.
How URLs get discovered
Search engines learn about URLs from several sources:
| Source | How it works | Typical limitation |
|---|---|---|
| Links on pages already known | The crawler extracts `href` values from fetched HTML | The page must be linked from somewhere |
| External links | Another site links to yours | You don't control these |
| XML sitemaps | You list URLs in a file you submit or reference | A listing helps discovery but doesn't make a page important |
| Previous crawls | The engine recrawls URLs it already knows | A URL must have been known once |
| Manual submission | You request indexing in a webmaster tool | Doesn't scale, and gives no structure |
Links are the main route. A sitemap is a useful backup, but it carries no information about how pages relate to each other. A link does. When page A links to page B, the engine learns that B exists, that the author considers it worth visiting from A, and what A calls it. That last piece is the anchor text, covered in a later chapter.
A small crawler model
The following program mimics the crawl loop on a tiny in-memory site. Each key is a page, and each value is the list of pages it links to. The crawler starts at the home page and uses breadth-first search, so it finds pages in order of click distance.
from collections import deque
# Each page maps to the internal URLs it links to
site = {
"/": ["/blog/", "/about/"],
"/blog/": ["/blog/url-slugs/", "/blog/internal-links/"],
"/about/": [],
"/blog/url-slugs/": ["/blog/internal-links/"],
"/blog/internal-links/": [],
"/old-landing-page/": ["/"], # links out, but nothing links to it
}
def crawl(start, links):
depth = {start: 0}
queue = deque([start])
while queue:
url = queue.popleft()
for target in links.get(url, []):
if target not in depth: # skip pages already seen
depth[target] = depth[url] + 1
queue.append(target)
return depth
found = crawl("/", site)
for url, d in sorted(found.items(), key=lambda item: (item[1], item[0])):
print(d, url)
orphans = set(site) - set(found)
print("Not discovered:", sorted(orphans))Running it prints:
0 /
1 /about/
1 /blog/
2 /blog/internal-links/
2 /blog/url-slugs/
Not discovered: ['/old-landing-page/']Three ideas show up in this output.
- Reachability. Every page the crawler printed is reachable by following links from the start page.
- Depth. The number beside each URL is its click depth, the fewest clicks needed to reach it from the home page. Real engines don't use click depth as a fixed rule, but pages far from the home page tend to be crawled less often and seen as less important.
- Orphans.
/old-landing-page/exists and links to the home page, but no crawled page links to it. A page like this is an orphan page. Unless a sitemap or an external link reveals it, the crawler never finds it.
A real crawler differs in many ways. It runs many fetchers at once, honors a per-site rate limit, and prioritizes URLs by estimated value. The reachability model still holds.
What counts as a followable link
The crawler extracts URLs from specific places in the HTML. The most reliable one is an a element with an href attribute that holds a resolvable URL.
<!-- Followed: a real link to a real URL -->
<a href="/blog/url-slugs/">guide to URL slugs</a>
<!-- Not followed as a link: no href -->
<a onclick="goTo('/blog/url-slugs/')">guide to URL slugs</a>
<!-- Not a page link: it points inside the current page -->
<a href="#section-2">Jump to section 2</a>Rules that cause common errors:
- Relative URLs are resolved against the current page. The link
href="guides/"on/blog/post/points to/blog/post/guides/. The linkhref="/guides/"points to/guides/. Mixing these up creates links to pages that don't exist. - Fragments don't create pages.
/page/#topand/page/are the same document to a crawler. - A click handler isn't a link. Navigation done only through JavaScript events, such as
onclickon aspan, gives the crawler nothing to extract. The next chapters return to this. - Only the URL matters for discovery. A link in a hidden menu is still extracted if the markup is in the HTML. A link that exists only after a user action, such as scrolling to trigger a load, may never be discovered.
What the crawler does with each response
Discovery depends on what happens when a URL is fetched.
| Response | Effect on discovery |
|---|---|
| 200 with HTML | The page's links are extracted and queued |
| 301 or 302 redirect | The crawler follows to the new URL, but only up to a limit of hops. Google follows up to 10 |
| 404 or 410 | A dead end. The page drops out of the index over time, and its outgoing links are lost |
| 5xx | Treated as temporary. Repeated errors make the crawler slow down |
| Blocked by `robots.txt` | The page isn't fetched, so its links are never read |
Two details deserve attention.
First, a robots.txt block stops crawling, not indexing. A blocked URL can still be indexed from external links, with no content. It also blocks discovery through that page, because the crawler can't read its links. If you want a page excluded from results, a noindex directive on a crawlable page is the tool, since the crawler must be able to fetch the page to see the directive.
Second, redirect chains waste crawl effort. If /a redirects to /b, which redirects to /c, the crawler spends three requests to reach one page. Pointing internal links straight to the final URL avoids this. A later chapter covers it in detail.
Crawl budget in practice
Search engines don't fetch every URL on every site every day. Crawl budget is the number of URLs a bot is willing and able to fetch from your site in a period. It depends on how quickly your server answers and how valuable the engine thinks your content is.
For most small and medium sites, crawl budget isn't a problem. It becomes relevant on large sites with many near-duplicate URLs, such as filter combinations that produce thousands of addresses. In that case the crawler may spend its visits on low-value URLs and reach important pages late. Clear link structure and canonical URLs, both covered later, keep the crawler's attention on the right pages.
Common errors at this stage
- Orphan pages. A page was published but never linked from the navigation, category pages, or other posts.
- Links hidden behind scripts. Menus built from
spanelements or generated only after interaction. - Links to the wrong URL form. For example, links to
http://when the site serveshttps://, or to a version with a trailing slash that redirects. - Broken links. A link to a URL that returns 404. The crawler spends a request and learns nothing.
- Relying only on the sitemap. A sitemap-only page is discovered but has no links telling the engine how it relates to the rest of the site.
- Blocking in robots.txt and expecting
noindexto work. The crawler never sees the directive.
How this connects to the rest of the tutorial
The discovery model gives each later topic a purpose:
- The URL and slug chapters decide what the discovered address looks like and how stable it stays.
- The internal link chapters decide which pages the crawler reaches, and how quickly.
- The anchor text chapters decide what the crawler learns about the target page from the link.
- The audit chapter uses the idea you just saw in the crawl program: crawl your own site, compare what is reachable with what exists, and fix the gap.
Exercise
In the crawl program above, you add a new page "/blog/new-post/" to the site dictionary, but no other page lists it in its links. After running crawl("/", site), will "/blog/new-post/" appear in the output, and what would you change so it does?
Show answer
It will not appear. The crawler only follows links from pages it has already reached, so a page with no inbound links is an orphan and ends up in the "Not discovered" list. To fix it, add "/blog/new-post/" to the link list of a reachable page, for example "/blog/", which puts it at click depth 2.
Exercise
A page is blocked in robots.txt and also carries a noindex meta tag. You expected it to disappear from search results, but the URL still shows up. Why?
Show answer
The robots.txt rule stops the crawler from fetching the page, so it never reads the noindex tag. The URL can still be indexed from external links alone. To remove it, allow crawling so the noindex directive can be read, or use a removal method that doesn't depend on fetching the page.
Exercise
A navigation item is built as a span element with an onclick handler that changes location. Why is the target page at risk of not being discovered, and what is the minimal fix?
Show answer
A crawler extracts URLs from a elements with an href attribute. A span with a click handler has no href, so the crawler finds no URL to follow. The minimal fix is to replace the span with an a element whose href holds the target URL, and keep any JavaScript behavior as an enhancement.