A Title Tag Length Checker in 30 Lines of Python: Audit Every Page in Your Sitemap
I wrote this with help from an AI assistant for editing; the script, the run and the opinions are mine.
Every SEO tool has a title tag length checker, and most of them want an account before they show you anything. You don't need one. Your sitemap already lists every page you care about, and Python's standard library can fetch each one and read two tags.
This is the script I run on my own site, contento.solutions, with the real output from a run on 17 November 2026. No pip install, no API key.
What does a title tag length checker actually check?
It checks how long each page's <title> is, because Google cuts long ones in the results. Google's title link documentation is precise about it: there's no limit on how long a <title> element can be, but the title link is truncated "as needed, typically to fit the device width." The snippet documentation says the same about meta descriptions.
So any character limit is a heuristic, not a rule. Truncation depends on pixel width, not characters. I use 60 for titles and 160 for descriptions as a "look at this" threshold, and the script makes both easy to change.
The checks that matter more than length:
- A page with no
<title>at all. - Two pages with the same title, which makes them hard to tell apart in results.
- A page with no meta description, so Google builds the snippet from page text on its own.
The script
import re, sys, time, urllib.request from collections import Counter from html import unescape UA = {"User-Agent": "sitemap-audit/0.1 (+your-email@example.com)"} def get(url): req = urllib.request.Request(url, headers=UA) with urllib.request.urlopen(req, timeout=20) as r: return r.read().decode("utf-8", "replace") def first(pattern, html): m = re.search(pattern, html, re.I | re.S) return unescape(m.group(1)).strip() if m else "" site = sys.argv[1].rstrip("/") urls = re.findall(r"<loc>(.*?)</loc>", get(site + "/sitemap.xml")) rows = [] for url in urls: html = get(url) title = first(r"<title[^>]*>(.*?)</title>", html) desc = first(r'<meta\s+name="description"\s+content="([^"]*)"', html) rows.append((url, title, desc)) time.sleep(0.5) dupes = Counter(t for _, t, _ in rows) for url, title, desc in rows: issues = [] if not title: issues.append("no title") elif len(title) > 60: issues.append(f"title {len(title)} chars") if dupes[title] > 1: issues.append(f"title used {dupes[title]}x") if not desc: issues.append("no meta description") elif len(desc) > 160: issues.append(f"description {len(desc)} chars") if issues: print(url.replace(site, "") or "/", "|", ", ".join(issues)) print(f"\n{len(rows)} URLs checked, {sum(1 for r in rows if not r[2])} without a description") Thirty lines without the blank ones. Save it as audit_sitemap.py and run:
python audit_sitemap.py https://example.com How does it work, line by line?
-
get()fetches a URL with a named User-Agent. Put a real contact in it: if you ever run this on a site that isn't yours, the owner can see who's knocking. - The sitemap is parsed with a regex on
<loc>, which is enough for a flaturlset. If your sitemap is an index (<sitemapindex>), the<loc>values are child sitemaps, not pages: run the script once per child. -
first()returns the first match of a pattern, with HTML entities decoded. That matters:&in a title is one character on screen, five in the source. -
Countercounts how many pages share each title, so duplicates show up without a second pass. -
time.sleep(0.5)keeps it polite. On 78 URLs the run took a few minutes, which is fine for something you run once a month.
What did it find on a real site?
Here's the unedited output from my site (78 URLs in the sitemap):
/academy/schema-markup-for-local-business | title 64 chars /academy/google-reviews-fake-negative-missing | title 72 chars /academy/local-search-ai-map-pack | title 61 chars /academy/does-chatgpt-use-bing | title 80 chars /academy/ai-says-something-false-about-your-business | title 76 chars /academy/how-to-track-ai-traffic-in-ga4 | title 86 chars /academy/google-business-profile-suspended-appeal | title 69 chars /academy/does-faq-schema-still-work | title 76 chars /academy/the-block-nobody-declared | title 77 chars /academy/does-google-still-use-meta-description | title 80 chars, description 162 chars /academy/therapy-websites-ai-access | title 64 chars /blog/can-an-seo-agency-guarantee-rankings | title 69 chars /blog/why-cant-google-find-my-page-orphan-pages | title 71 chars /blog/does-google-penalize-ai-content | title 82 chars /blog/paying-to-be-on-a-list-vs-being-the-answer | title 75 chars /blog/website-if-you-have-google-business-profile | title 81 chars /blog/how-small-businesses-write-image-alt-text | title 77 chars /blog/what-website-response-time-measures | title 65 chars /blog/how-long-does-it-take-google-to-index-a-new-website | title 73 chars /blog/what-pages-does-a-small-business-website-need | title 67 chars /blog/how-i-built-contento-as-a-system | title 65 chars /blog/category/Search+foundations | title 77 chars, no meta description /blog/category/Measurement | title 70 chars, no meta description /blog/category/AI+visibility | title 72 chars, no meta description /blog/category/Cost+and+value | title 73 chars, no meta description /creative-lab | title 74 chars /seo-buenos-aires | title 63 chars /seo-miami | title 61 chars /seo-new-york | title 62 chars /seo-colombia | title 63 chars /seo-peru | title 63 chars /seo-uruguay | title 63 chars /seo-mexico | title 62 chars 78 URLs checked, 4 without a description Three things I read in it:
- Most long titles are long because of the suffix. The platform appends
| Contento Solutionsto every title. That's 21 characters before the page says anything. A 45 character headline becomes a 66 character title. If truncation worries you, the suffix is the first thing to shorten, because it's one setting instead of 33 edits. - No duplicates and no missing titles. The two checks I care most about came back clean, which is the useful part of an empty result.
- The four blog category pages have no meta description. That's the real finding. Category archives are easy to forget because nobody writes them; the platform generates them. They're in the sitemap, so they're worth one sentence each.
The 162 character description is two characters over my own threshold. I'd leave it.
What are the limits of a regex audit?
Regex on HTML is fragile, and I'd rather say it than have you find out:
- The description pattern expects
namebeforecontent. If your HTML writes<meta content="..." name="description">, it won't match. Check one page's source before trusting a "no meta description" line. For anything bigger than a monthly check, swap the regexes forhtml.parser. - It reads the served HTML only. If a JavaScript framework sets the title after load, the script sees whatever the server sent, which is also what a crawler that doesn't render sees first.
- Character count isn't pixel width. A title full of
WandMtruncates sooner than one full ofiandl.
Does title length affect rankings?
Google doesn't say it does. What it says is that long titles get truncated and that it may rewrite a title link when the <title> doesn't describe the page well. Length is a display problem; a vague title is a ranking and click problem.
How often should I run it?
Once a month, and after any template change. Templates are where a suffix or a missing description gets applied to dozens of pages at once.
Related reading on my site: does Google still use your meta description and finding orphan pages with curl and your sitemap. If you run the script on your own site, tell me in the comments which check fired first.
I write about SEO and AI visibility for service businesses at Contento Solutions.