Sub topic 1
How search engines find pages through links
Prerequisites
This chapter assumes you know basic HTML, including the a element and its href attribute. It also assumes you know that a browser requests a page over HTTP and gets back a status code such as 200 or 404. You should have a general idea of what SEO is. No other background is needed.
The working model: crawl, index, rank
A search engine cannot show a page that it has never found. Three steps happen before a page can appear in results:
- Crawling. A program called a crawler (Googlebot is Google's) requests URLs and downloads what they return.
- Indexing. The search engine analyzes the downloaded page and stores what it learned in a large database called the index.
- Ranking. When someone searches, the engine picks pages from the index and orders them.
This tutorial is mostly about the first step. Slugs and internal links exist, in part, to help crawlers reach your pages and understand them.
How a crawler discovers URLs
A crawler starts from a set of URLs it already knows. These come from earlier crawls, from sitemap files you submit, and from links on other pages. It downloads each page, extracts every link it finds, and adds the new URLs to a queue of pages to visit. Then it repeats the process.
Links are the main way this loop moves forward. If no page links to a URL, and it is not in a sitemap, the crawler may never find it. A page in that state is called an orphan page.
Why links matter for more than discovery
A link does two jobs:
- It gives the crawler a path. The link is how the crawler gets from one URL to another.
- It gives context. The anchor text, which is the visible clickable text of the link, and the text around it tell the search engine what the target page is about.
Links also hint at importance. A page that many other pages on your site link to, especially pages close to the home page, looks more significant than a page linked once from a deep corner. Later chapters cover how to use this on purpose.
Internal links and external links
An internal link points to another page on the same site. An external link points to a different site. You control internal links completely, so they are the easiest tool you have for guiding crawlers and readers. This tutorial focuses on them.
What a crawler needs from a link
For a link to work as a path, the crawler must be able to see a URL in the HTML. The reliable form is an a element with an href:
<a href="/guides/url-slugs/">guide to writing URL slugs</a>A crawler can read the destination (/guides/url-slugs/) and the description (the anchor text). A click handler on another element gives it neither, because there is no href to extract. Chapter 9 covers crawlable markup in detail.
Seeing links as a crawler does
The following script lists the links in a piece of HTML, along with their anchor text. It is a small model of the extraction step in the diagram.
from html.parser import HTMLParser
class LinkCollector(HTMLParser):
def __init__(self):
super().__init__()
self.links = []
self._href = None
self._text = []
def handle_starttag(self, tag, attrs):
if tag == "a":
self._href = dict(attrs).get("href")
self._text = []
def handle_data(self, data):
if self._href is not None:
self._text.append(data)
def handle_endtag(self, tag):
if tag == "a" and self._href is not None:
anchor = " ".join("".join(self._text).split())
self.links.append((self._href, anchor))
self._href = None
parser = LinkCollector()
parser.feed('<p>Read the <a href="/guides/url-slugs/">guide to URL slugs</a> or <a href="/more/">click here</a>.</p>')
print(parser.links) # [('/guides/url-slugs/', 'guide to URL slugs'), ('/more/', 'click here')]The output has two entries. The first anchor describes its target. The second, "click here", tells a reader or crawler nothing about /more/.
Common errors at this stage
| Problem | What happens | Typical cause |
|---|---|---|
| Orphan page | Crawler finds no path to the page | New page published without any link to it |
| Link without `href` | Crawler sees no URL to follow | Navigation built from click handlers |
| Link to a 404 | Crawler reaches a dead end | Page deleted or slug changed without a redirect |
| Generic anchor text | Link gives no context | "Click here" or "read more" |
Where the rest of the tutorial goes
The next chapters look at the URL itself and at the slug, the readable part that identifies a page. After that, the tutorial returns to links, anchor text, and site structure, and ends with an audit that finds the problems in the table above.
Exercise
A new article is published and added to your sitemap, but no other page on your site links to it. What is this kind of page called, and why is it a weak position even though the sitemap lists it?
Show answer
It is an orphan page. The sitemap can tell the crawler the URL exists, but without internal links the page gets no path from other pages, no anchor text describing it, and no signal that it matters. Linking to it from a relevant hub or related article fixes this.
Exercise
A menu item is written as <span onclick="location.href='/pricing/'">Pricing</span>. Why might a crawler fail to follow it, and what is the fix?
Show answer
The element is not an a element and has no href, so the HTML contains no URL for the crawler to extract. Replace it with <a href="/pricing/">Pricing</a>.