Sub topic 16
Diagnosing why a page is not crawled or indexed
This chapter assumes you know HTTP status codes, basic HTML, and short Python snippets. It also assumes you have read the earlier chapters on robots.txt, sitemaps, canonicalization, and indexing controls. Here you put them together into one ordered checklist.
Crawled versus indexed
A page can fail at two different points. Either the crawler never fetched it, or it fetched the page and decided not to store it in the index. These need different fixes, so first work out which one happened. Server logs help. If the crawler's user agent never requested the URL, the problem is discovery or permission. If it did request the URL, look at the response and at the page itself.
Check the causes in order
Work from the earliest stage to the latest. A problem early in the pipeline hides every problem after it.
- Discovery. Is the URL linked from a crawled page, or listed in a sitemap? A page with no inbound links is an orphan and may never be found.
- Permission. Does robots.txt allow your crawler to fetch it? Test the rule instead of guessing.
- HTTP response. Does the URL return 200? Check for 404 and 410 responses, 5xx errors, timeouts, and long redirect chains.
- Rendering. If the text is added by JavaScript, is it present after rendering? A fetched page with an empty shell has little to index.
- Indexing directives. Look for a
noindexmeta tag or anX-Robots-Tagheader. - Canonical and duplicates. Does a canonical tag point to another URL, or is the page near-identical to another one?
- Freshness and priority. If everything above is fine, the page may simply be waiting for its next crawl.
Test robots.txt and the response
This script checks the two cheapest causes, permission and status code. It reports the final URL after redirects.
from urllib.error import HTTPError
from urllib.parse import urlparse
from urllib.request import urlopen
from urllib.robotparser import RobotFileParser
def check(url, agent="ExampleBot"):
parts = urlparse(url)
rp = RobotFileParser()
rp.set_url(f"{parts.scheme}://{parts.netloc}/robots.txt")
rp.read()
print("allowed by robots.txt:", rp.can_fetch(agent, url))
try:
with urlopen(url, timeout=10) as resp:
print("status:", resp.status, "final URL:", resp.geturl())
print("X-Robots-Tag:", resp.headers.get("X-Robots-Tag"))
except HTTPError as err:
print("status:", err.code)
check("https://example.com/private/data.html")Common misreadings
- A robots.txt block stops fetching, not indexing. A blocked URL can still appear in results if other pages link to it.
- A
noindextag only works if the crawler can fetch the page. If robots.txt blocks the page, the crawler never sees the tag. - A sitemap entry is a hint, not a command. It does not force a page into the index.
- A page can be crawled and still left out because it is a duplicate or has little unique content.
Exercise
A page returns 200, is allowed by robots.txt, and is listed in your sitemap, but it is not indexed. Its HTML contains <meta name="robots" content="noindex, follow">. What is the cause, and what should you change?
Show answer
The noindex directive tells the search engine not to store the page, and the crawler can fetch the page, so it sees the tag. Remove the noindex tag (or change it to allow indexing) and wait for the page to be recrawled.
Exercise
You added Disallow: /old/ to robots.txt and a noindex tag to pages under /old/ to remove them from results. The pages are still listed. Why?
Show answer
The Disallow rule stops the crawler from fetching the pages, so it never sees the noindex tag. Remove the Disallow rule, let the pages be recrawled so the noindex is read, and only block them afterward if you still want to.