A page can be live, indexed in the sitemap and well written, and still do nothing, because no other page on the site links to it. Search engines find pages mostly by following links, and Google's own guidance on crawlable links is blunt: links should be real anchor elements with an href that resolves.

On a small business site this problem builds up quietly. A new service page gets published but never added to the menu. A blog post is written, then the post that should have pointed to it is never edited. Six months later the pages that matter most have the fewest internal links.

Here is a short script that finds it. It uses only the Python standard library.

What the script checks

  1. It reads the sitemap and treats every URL in it as a page that should be reachable.
  2. It fetches each page and collects the internal links in the body.
  3. It counts how many other pages link to each URL.
  4. It reports orphans (zero inbound links) and weak pages (one inbound link).

It is a rough crawl, not a replacement for a proper crawler, but for a site of up to a few hundred pages it answers the question in under a minute.

The script

import sys, re, urllib.request from html.parser import HTMLParser from urllib.parse import urljoin, urlparse, urldefrag from collections import defaultdict SITE = sys.argv[1].rstrip("/") # e.g. https://example.co.uk HOST = urlparse(SITE).netloc def get(url): req = urllib.request.Request(url, headers={"User-Agent": "link-check/1.0"}) with urllib.request.urlopen(req, timeout=20) as r: return r.read().decode("utf-8", "replace") class Links(HTMLParser): def __init__(self): super().__init__() self.hrefs, self.skip = [], 0 def handle_starttag(self, tag, attrs): if tag in ("nav", "footer", "header"): self.skip += 1 if tag == "a" and not self.skip: href = dict(attrs).get("href") if href: self.hrefs.append(href) def handle_endtag(self, tag): if tag in ("nav", "footer", "header") and self.skip: self.skip -= 1 pages = re.findall(r"<loc>(.*?)</loc>", get(SITE + "/sitemap.xml")) pages = [p.strip() for p in pages if p.endswith("/") or "." not in p.split("/")[-1]] known = {urldefrag(p)[0].rstrip("/") for p in pages} inbound = defaultdict(set) for page in pages: try: parser = Links() parser.feed(get(page)) except Exception as e: print("could not fetch", page, e) continue for href in parser.hrefs: target = urldefrag(urljoin(page, href))[0].rstrip("/") if urlparse(target).netloc == HOST and target in known and target != page.rstrip("/"): inbound[target].add(page) for url in sorted(known, key=lambda u: len(inbound[u])): n = len(inbound[url]) if n <= 1: print(("ORPHAN" if n == 0 else "WEAK "), url) 

Run it with python3 links.py https://example.co.uk. If your sitemap is an index of other sitemaps (WordPress with an SEO plugin usually does this), point the get call at each child sitemap and join the lists.

Two choices worth explaining

It ignores nav, header and footer links on purpose. A link in the main menu appears on every page, so it would make everything look well linked. What you want to know is which pages are linked from the content, because that is where a link carries context. If a page is only reachable through the footer, treat it as weak.

It only counts pages in the sitemap. That keeps the report to pages you intend to be found. If a URL is in the sitemap and gets zero content links, either link it or ask why it is there.

Reading the output

  • Orphans are the first job. Find the two or three existing pages where a sentence about that topic would be natural, and add a link with a descriptive anchor ("our guide to boiler servicing", not "click here").
  • Weak pages matter most when they are money pages. A service page with one inbound link and a blog with fifteen is a sign the site is organised around what was easy to write, not what earns enquiries.
  • Pages with many inbound links but no commercial purpose (an old news post, a thank-you page) can pass some of that weight on by linking to the relevant service page in return.

What to hand over

For a local business site, I attach three things to the handover: the script output before and after, a one-line note of which service pages are linked from which posts, and a reminder that every new post should link to at least one service page. It takes ten minutes to explain and saves a lot of drift.

If you build sites for local clients and want the wider picture of what a local search programme covers beyond links and code, the team behind this write-up is an SEO company in Birmingham that works on this kind of site structure alongside content and local listings.

Run it on a site you built last year. Most developers find at least one important page with no inbound links.

Rocky V, Head of Operations, DigitalCave