Sub topic 1
The big picture: crawl, index, serve
Prerequisites
Assume you understand HTTP requests and responses, common status codes, HTML links, and short Python snippets. A crawler is a program that fetches web pages. An index is a data structure that stores information about page content.
Crawl, index, serve
Search systems usually follow three stages:
- Crawl: discover URLs and fetch allowed pages.
- Index: extract text and metadata, remove duplicates, and store searchable terms.
- Serve: match a user’s query against the index and rank suitable pages.
A search engine may discover a URL from a link, a sitemap, or another source. Discovery does not guarantee fetching or indexing.
Fetching a page: requests, status codes, and redirects
The crawler sends an HTTP request, usually a GET, and receives a response. A 200 response contains the page. A 404 means the resource was not found. A 5xx status indicates a server problem, so the crawler may retry later.
A redirect, such as 301 or 302, points to another URL. The crawler follows it subject to its policies, then evaluates the final response. Repeated redirects, redirect loops, timeouts, and unsupported content can stop processing.
robots.txt: what a crawler may fetch
Before crawling a site, a crawler commonly requests /robots.txt. This file contains rules for named user agents. Disallow limits fetching, while Allow can create an exception.
User-agent: *
Disallow: /private/
Allow: /private/public-report.htmlThese rules guide cooperative crawlers. They do not protect private data. Also, robots.txt controls fetching, not indexing. A page that is fetched can instead request removal with a noindex directive.
> callout note > A blocked URL may still be known from links or a sitemap. Blocking its fetch does not erase every reference to it. > ```
Parsing HTML and extracting links
After fetching HTML, the crawler parses elements such as <a href="...">. It extracts links, then adds eligible URLs to its discovery queue. A page can therefore expand the crawl even when it contains little visible text.
Discovering and normalizing URLs
Normalization converts equivalent-looking URLs into a consistent form. The crawler resolves relative links, removes fragments such as #details, and checks the scheme and host. It also records already seen URLs to prevent repeated work.
Normalization must be conservative. Query parameters can change the page, so removing them blindly may lose content. Canonicalization and duplicate handling later decide which equivalent pages should represent the content.
Exercise
Does a Disallow rule mean that a page cannot appear in a search index?
Show answer
No. It asks cooperative crawlers not to fetch the page. It does not guarantee removal from the index.