A small metadata extractor can hide a useful clue if it returns only the first canonical link. Keep the declarations you observed, then decide what to repair.

Here is a repeatable saved-HTML check using Python's standard library. It starts with one local file and keeps HTTP, rendering and indexing observations separate.

Disclosure: I work on AppStruct. This tutorial was prepared with AI assistance; the Python examples below were executed locally. This is a small source-inspection exercise, not a complete SEO audit. The two canonical URLs in the fixture are fictional.

Preserve the duplicate before interpreting it

Save the following as canonical-example.py, then run python3 canonical-example.py:

from html.parser import HTMLParser class CanonicalLinks(HTMLParser): def __init__(self): super().__init__() self.links = [] def handle_starttag(self, tag, attrs): values = dict(attrs) rel = (values.get("rel") or "").lower().split() if tag == "link" and "canonical" in rel: self.links.append(values.get("href") or "") fixture = ( '<link rel="canonical" href="https://example.com/catalog">' '<link rel="alternate CANONICAL" href="/old-catalog">' ) parser = CanonicalLinks() parser.feed(fixture) parser.close() assert parser.links == ["https://example.com/catalog", "/old-catalog"] print(parser.links) 

The assertion expects two declarations in their original order. The relative URL remains relative. This tiny fixture does not decide which URL should be canonical, and it does not inspect template or JavaScript behavior. Its purpose is to make a first-match-only extraction error easy to reproduce.

Google's canonicalization guidance describes a canonical declaration as a signal for a preferred URL. A declaration in collected HTML does not tell us which canonical Google selected.

Save one public response

For a public page you are authorized to inspect:

curl --silent --show-error --dump-header headers.txt --output page.html https://example.com/ 

Keep the requested URL and collection time with the two files. This command does not follow redirects or execute JavaScript. If it returns a redirect, inspect that response and destination before collecting the intended final page. Keep authenticated HTML and private URLs out of public reports.

Read canonical links from your saved file

Add the following below the fixture check in the same canonical-example.py file, with a UTF-8 page.html beside it:

from pathlib import Path observed = CanonicalLinks() observed.feed(Path("page.html").read_text(encoding="utf-8")) observed.close() print(observed.links) 

Run python3 canonical-example.py. The first printed list is the two-link fixture; the second contains the canonical href values observed in the saved file, in source order. An empty href stays empty. A relative value stays relative; this code does not resolve it against the requested URL or a base element.

An empty list means this parser observed no canonical declaration in that file. It does not establish that the rendered page lacks one. The parser does not execute JavaScript or apply a browser's tree-building rules. It can also encounter markup inside source templates, so inspect the surrounding source before interpreting a declaration as active page content.

This check makes no network requests. It does not evaluate response headers, redirects, robots.txt, Google indexing, search performance, backlinks or page speed. Keep those as separate observations. Use a small, trusted local file; this example has no input-size limit or audit-report format.

Make the next check specific

Suppose the collected HTML has two different canonicals. Record both, identify the template or integration that supplied each, decide the intended public URL, then collect the same page again after the change. Check the HTTP headers and rendered page separately. Use Search Console for Google's observations.

A result worth sharing is a reproducible finding attached to a URL and a retest. A metadata count is not a ranking score.

Implementation reference: Python HTMLParser documentation. The parser calls handlers for the source markup; it does not implement a browser's complete tree-building and rendering behavior.