Sub topic 3
How crawlers discover and record links
This chapter assumes you can read simple HTML, know what a URL is, and know that search engines crawl pages before they index them. You should also know what a backlink is, from the previous chapter. Here you will see the machinery behind that definition: how a crawler finds a link, and what it stores once it has found one.
Why discovery comes first
A backlink only counts if the search engine knows about it. A link that sits in a page the crawler has never fetched, or that the crawler cannot parse as a link, has no effect on the target's ranking. Most "my links are not showing up" problems come from this stage, not from the ranking stage.
A crawler is a program that fetches pages over HTTP and extracts the links in them. The links it extracts become the next pages to fetch. Discovery and recording are two separate jobs:
- Discovery decides which URLs get fetched.
- Recording stores facts about the links found on fetched pages.
The crawl loop
Every crawler, from a 50-line script to a search engine's fleet, runs a version of the same loop.
The steps in order:
- Seeds. The crawler starts from URLs it already knows: previously crawled pages, submitted sitemaps, and links found elsewhere.
- Frontier. The frontier is the queue of URLs waiting to be fetched. A real frontier is prioritized, so important or frequently changing pages come up sooner.
- Permission check. The crawler reads the site's
robots.txtfile and skips URLs the site disallows. - Fetch. The crawler requests the URL and follows redirects.
- Parse. The crawler reads the HTML and pulls out every link.
- Normalize and record. Each link is turned into a canonical absolute URL, and the relationship is stored.
- Enqueue. Targets not yet seen are added to the frontier.
Step 7 is how one backlink leads to discovery of a whole site. If a well-crawled page links to your new page, the crawler finds your page without any submission.
What counts as a discoverable link
Crawlers extract links from specific places. The most reliable one is an anchor element with an href attribute.
<a href="/pricing">Pricing</a>Several patterns look like links to a human but may not be links to a crawler:
| Pattern | Discoverable? | Why |
|---|---|---|
| `<a href="/page">text</a>` | Yes | A standard anchor with a resolvable URL. |
| `<a href="/page" rel="nofollow">text</a>` | Yes, as a hint | The link is recorded with its `rel` value. How it is used is the engine's decision. |
| `<span onclick="go('/page')">text</span>` | No | No `href`. The URL exists only in a script handler. |
| `<a href="javascript:void(0)">text</a>` | No | The `href` is not a fetchable URL. |
| `<a>` with the URL set later by JavaScript | Sometimes | Only if the engine renders the page and sees the final DOM. |
| `<a href="mailto:[email protected]">` | No | Not an HTTP URL. |
| A URL in plain text, such as `https://example.com/x` | Sometimes | Some engines treat bare URLs as weak discovery hints. Do not rely on it. |
Google's own documentation recommends using <a> elements with href attributes for any link you want crawled. Other mechanisms, such as button clicks and script-only navigation, are not dependable.
Rendering and JavaScript
Many modern pages build their content in the browser. A crawler that only reads the raw HTML response sees the page before any scripts run. Search engines such as Google can queue a page for rendering, running it in a headless browser and reading the final DOM. Rendering is more expensive than parsing raw HTML, so it often happens later than the first fetch.
This has a practical consequence for backlinks. A link that exists only after JavaScript runs may be recorded later than a link in the raw HTML, or not at all if rendering fails or is blocked. A link present in the server's HTML response is the safest choice.
Turning a link into a recorded edge
Extracting href is not enough. The value in the HTML is often relative, and the same page can be reached through many spellings of its URL. Before recording an edge, the crawler normalizes the target.
Common normalization steps:
- Resolve relative URLs. On
https://a.example/blog/post, the link../aboutbecomeshttps://a.example/about. A<base href>element in the page changes the base used for this resolution. - Drop fragments.
https://a.example/page#sectionandhttps://a.example/pageare the same document. The fragment is handled by the browser and is not sent to the server. - Lowercase the scheme and host. Hostnames are case-insensitive. Paths usually are not.
- Filter schemes. Keep
httpandhttps. Dropmailto:,tel:, andjavascript:. - Apply canonical hints and redirects. If the target redirects to another URL, or the page declares a
rel="canonical"URL, the engine may attribute the link to the final canonical URL.
Normalization matters for backlinks because links are counted per target. If https://a.example/page and https://a.example/page#top were stored as different targets, one page's inbound links would be split across two entries.
What gets stored
For each link, the crawler stores an edge in the link graph. An edge records at least:
- the source URL, which is the page that contains the link
- the target URL, which is the normalized destination
- the anchor text, which is the visible text inside the
<a>element - the rel values, such as
nofollow,sponsored, orugc - the time the link was seen
A backlink is simply an edge viewed from the target's side. The crawler stores it as an outgoing link of the source page. The target's inbound links are found by reading the same set of edges grouped by target. This is why a link-checking tool and a search engine can both report "links to your page": both invert the same graph.
Internal and external edges
The same edge structure holds both internal links and external links. What differs is the host. An edge whose source and target share a host is internal. An edge across hosts is external. For the target site, external edges are backlinks.
A working miniature
The following program does the full job on a small simulated web. It parses links, normalizes them, stores edges with anchor text and rel, and then reports the external edges. It uses a dictionary in place of HTTP so that it runs anywhere.
from collections import deque
from html.parser import HTMLParser
from urllib.parse import urljoin, urldefrag, urlsplit
class LinkCollector(HTMLParser):
"""Collect href, rel values, and anchor text for every <a> tag."""
def __init__(self):
super().__init__()
self.links = []
self._current = None
def handle_starttag(self, tag, attrs):
if tag == "a":
attributes = dict(attrs)
if "href" in attributes:
self._current = {
"href": attributes["href"],
"rel": (attributes.get("rel") or "").split(),
"text": "",
}
def handle_data(self, data):
if self._current is not None:
self._current["text"] += data
def handle_endtag(self, tag):
if tag == "a" and self._current is not None:
self._current["text"] = self._current["text"].strip()
self.links.append(self._current)
self._current = None
def normalize(base, href):
"""Resolve href against base, drop the fragment, keep only http(s)."""
absolute, _fragment = urldefrag(urljoin(base, href))
parts = urlsplit(absolute)
if parts.scheme not in ("http", "https"):
return None
return parts._replace(netloc=parts.netloc.lower(), path=parts.path or "/").geturl()
PAGES = {
"https://a.example/": (
'<a href="/about">About</a> '
'<a href="https://b.example/post#intro" rel="nofollow">B post</a>'
),
"https://a.example/about": (
'<a href="../">Home</a> <a href="mailto:[email protected]">Mail</a>'
),
"https://b.example/post": (
'<a href="https://a.example/about" rel="ugc">A about</a>'
'<a href="https://c.example/">C</a>'
),
}
def crawl(seeds):
frontier = deque(seeds)
seen = set(seeds)
edges = []
while frontier:
url = frontier.popleft()
html = PAGES.get(url)
if html is None: # stands in for a failed fetch
continue
collector = LinkCollector()
collector.feed(html)
for link in collector.links:
target = normalize(url, link["href"])
if target is None:
continue
edges.append((url, target, link["rel"], link["text"]))
if target not in seen:
seen.add(target)
frontier.append(target)
return edges
edges = crawl(["https://a.example/"])
for source, target, rel, text in edges:
if urlsplit(source).hostname != urlsplit(target).hostname:
print(f"{source} -> {target} rel={rel} text={text!r}")Running it prints the three external edges:
https://a.example/ -> https://b.example/post rel=['nofollow'] text='B post'
https://b.example/post -> https://a.example/about rel=['ugc'] text='A about'
https://b.example/post -> https://c.example/ rel=[] text='C'Points to notice in the result:
- The fragment
#introwas removed, so the target ishttps://b.example/post, a page the crawler then fetched. - The
mailto:link produced no edge. - The link to
https://c.example/was recorded even though that page was never fetched. The edge exists as soon as the source page is parsed. The crawler would learn aboutc.examplefrom this link alone. - Both
nofollowandugcedges were stored, with theirrelvalues. Storing a link is separate from deciding how much weight it carries.
Gaps between a link existing and a link being counted
A backlink can exist on the web and still not be in a search engine's graph. The common reasons:
- Blocked by robots.txt. If the linking page is disallowed, the crawler never fetches it and never sees its links. If the target is disallowed, the edge can still be recorded, but the crawler cannot read the target's content.
- Linking page never discovered. A page with no inbound links and no sitemap entry may sit unvisited. Links on deep, orphaned pages are discovered late.
- Crawl budget. A search engine allots a limited amount of fetching to each site, based on server capacity and how much it wants the content. Low-value or duplicate pages near the end of the queue may wait a long time.
- Server errors and slow responses. A page that returns 5xx errors or times out gets fetched less often.
- Noindex or removed pages. A page excluded from the index may still be crawled, but links on pages that are dropped entirely tend to lose their effect.
- Delay. Even a successful fetch is not instant. New links often appear in tools days or weeks after publication.
Discovery signals you control
You cannot make another site link to you, but you can help crawlers find and recognize links to your own pages.
- Submit an XML sitemap. It lists your canonical URLs and gives crawlers a second route to them besides links.
- Link your own pages together. Internal links carry crawlers to deep pages. An orphaned page has no internal route in.
- Keep targets stable. If a linked page is deleted, the backlink points to a 404 and is wasted. Use a 301 redirect to the new location.
- Pick one canonical URL. Serve one version of the page, with a consistent scheme, host, and trailing-slash policy, so inbound links are not split across variants.
Common errors
- Assuming a visible link is a crawlable link. Use browser developer tools to confirm the element is an
<a>with anhrefin the page source. - Counting URL variants as separate pages. Fragments, tracking parameters, and case differences can make one page look like several.
- Treating "recorded" as "ranked". Recording a link is the first step. Chapters ahead explain how its value is weighed.
- Expecting instant results. A new link needs discovery, fetching, parsing, and processing before it shows up in tools.
Exercise
A blog post on another site contains <a href="/tools/seo-checker?ref=blog#pricing">, and the post lives at https://Blog.Example/2026/review. Your tool recorded the target as https://blog.example/tools/seo-checker?ref=blog. Name two normalization steps that produced this result, and say what would need to be true for this link to count as a backlink to your site https://seo.example.
Show answer
The relative URL was resolved against the base URL, which turned /tools/seo-checker... into an absolute URL on the linking page's own host. The fragment #pricing was dropped. The host was also lowercased. The recorded target is on blog.example, the same host as the source, so this is an internal link and not a backlink to seo.example. For it to be a backlink to your site, the href would have to be an absolute URL on seo.example, so that the source host and target host differ.
Exercise
A partner says they added a link to your page, but it does not appear in any backlink tool after three weeks. The link is written as <button onclick="location.href='https://seo.example/guide'">Read the guide</button>. What is the most likely cause, and what is the fix?
Show answer
A button with an onclick handler has no <a> element and no href, so a crawler does not treat it as a link. Even if the page is rendered, the URL exists only inside script behavior. The fix is to replace it with <a href="https://seo.example/guide">Read the guide</a>, styled as a button if needed.