For most local businesses, the phone number is the conversion. A plumber, a vet clinic or a physiotherapist gets more value from one tapped "Call" button than from a page view. Yet phone links are the part of a site that nobody re-tests after a redesign. The number looks right on the page, so nobody notices that the link behind it is broken, points at an old line, or is not a link at all.
This tutorial builds a small Python script, standard library only, that reads a sitemap, fetches every page and reports:
-
tel:links that break the format in RFC 3966 (spaces,tel://, keypad letters, a local number with no country code), - non-standard phone links such as
callto:, - links whose visible text shows one number while the
hrefdials another, - phone numbers in the page text that are not links at all,
- a summary of every distinct number the site actually links to.
I ran it for real against a small fictional site served on localhost, so every line of output below is real output from the script. The site, "Alder & Finch Veterinary Clinic", is made up for this tutorial, and every number uses the 555-01xx range that is set aside for fiction.
Disclosure: I work on Appie.run. Two free sitemap tools on appie.run are mentioned near the end; the script does not need them.
What the standard says (and what it does not)
The tel: URI scheme is defined in RFC 3966. I re-read it on 3 Dec 2026 (rfc-editor.org/rfc/rfc3966). The parts that matter for an audit:
- Use the global form. Section 5.1 says phone numbers MUST use the global (E.164) form, starting with
+and the country code, unless they cannot be written that way. Local numbers MUST carry aphone-contextparameter. - No spaces. Section 5.1.1 says
telURIs MUST NOT use spaces as visual separators. Allowed separators are-,.,(and). - No keypad letters. Section 5.1.2 says the URI format does not support numbers written as words, like 1-800-FLEA-VET.
- Extensions are a parameter.
tel:+15035550142;ext=2is the defined way to add an extension. - There is no
//. The grammar is"tel:"followed directly by the number, sotel://5035550142is not the form the RFC defines.
RFC 3966 also says implementations must not assume a minimum or maximum length, so the script does not check length. It cannot tell you whether a number is the right one; for that, a person has to compare against the client's records.
Two things the RFC does not tell you, so the script treats them as warnings rather than errors:
- Plenty of devices dial
tel:5035550142fine. The warning is that a link with no+is ambiguous for a visitor abroad. - Whether a plain-text number becomes tappable depends on the device and browser guessing. A real
tel:link is the only version that does not depend on a guess.
The fixture site
The fixture is a five-page site with a sitemap at http://localhost:8503/sitemap.xml. In its "before" state it has the kinds of problems that build up on small business sites:
- the header "Call" link on every page is
tel:+1 503 555 0142, with spaces (a template problem, so it repeats on every page), - the home page shows "Call 503-555-0142" as plain text,
- the services page footer uses
tel://5035550142, - the emergency page says "Call the after-hours line: 503-555-0198" but the link dials the main line,
+15035550142, - the contact page shows the main number as plain text, and the extension link has no
+country code, - a blog post links a keypad-letters number (
tel:1-800-FLEA-VET) and acallto:link.
The "after" state fixes all of them. The server script is serve_fixture.py, started with python3 serve_fixture.py before or python3 serve_fixture.py after; it only listens on 127.0.0.1.
The script
Everything is in one file, phone_audit.py. It uses urllib, xml.etree, html.parser, re, csv and collections, nothing else.
"""Audit click-to-call links across a sitemap. Standard library only. Usage: python3 phone_audit.py https://example.com/sitemap.xml [--csv report.csv] Checks, per page: - tel: links that break RFC 3966 (spaces, "tel://", keypad letters, local number with no phone-context) - callto: and other non-standard phone schemes - a tel: link whose visible text shows a different number than its href - phone numbers in the visible text that are not inside a tel: link Then one INFO line per distinct number found in tel: links. Exit code 1 if any ERROR is found, else 0. """ import argparse import csv import re import sys import urllib.error import urllib.request import xml.etree.ElementTree as ET from collections import Counter, defaultdict from html.parser import HTMLParser from urllib.parse import unquote UA = "phone-audit/1.0 (+standard library script)" NS = {"sm": "http://www.sitemaps.org/schemas/sitemap/0.9"} # North American style numbers: (503) 555-0142, 503-555-0142, 503.555.0142, +1 503 555 0142 PHONE_RE = re.compile(r"(?<![\w/])(?:\+?1[\s.-]?)?(?:\(\d{3}\)|\d{3})[\s.-]?\d{3}[\s.-]?\d{4}(?!\d)") SKIP_TAGS = {"script", "style", "noscript", "template"} def fetch(url, timeout=15): req = urllib.request.Request(url, headers={"User-Agent": UA}) try: with urllib.request.urlopen(req, timeout=timeout) as resp: return resp.status, resp.headers.get("Content-Type", ""), resp.read().decode("utf-8", "replace") except urllib.error.HTTPError as e: return e.code, e.headers.get("Content-Type", ""), "" except (urllib.error.URLError, TimeoutError) as e: return None, "", str(e) def sitemap_urls(url): status, _, body = fetch(url) if status != 200: sys.exit(f"Could not read sitemap ({status}): {url}") root = ET.fromstring(body) if root.tag.endswith("sitemapindex"): out = [] for loc in root.findall("sm:sitemap/sm:loc", NS): out.extend(sitemap_urls(loc.text.strip())) return out return [loc.text.strip() for loc in root.findall("sm:url/sm:loc", NS)] class PhoneParser(HTMLParser): def __init__(self): super().__init__(convert_charrefs=True) self.skip = 0 self.cur = None # the <a> being read: dict(href, line, text) self.links = [] # every <a> with a phone-ish scheme self.loose = [] # (line, text) visible phone numbers outside a tel: link def handle_starttag(self, tag, attrs): if tag in SKIP_TAGS: self.skip += 1 elif tag == "a": href = (dict(attrs).get("href") or "").strip() self.cur = {"href": href, "line": self.getpos()[0], "text": ""} def handle_endtag(self, tag): if tag in SKIP_TAGS and self.skip: self.skip -= 1 elif tag == "a" and self.cur is not None: scheme = self.cur["href"].split(":", 1)[0].lower() if ":" in self.cur["href"] else "" if scheme in ("tel", "callto"): self.links.append(self.cur) self.cur = None def handle_data(self, data): if self.skip: return if self.cur is not None: self.cur["text"] += data if self.cur["href"].lower().startswith("tel:"): return # linked: not "loose" for m in PHONE_RE.finditer(data): self.loose.append((self.getpos()[0], m.group(0))) def digits(s): return re.sub(r"\D", "", s) def same_number(a, b): """True if one digit string is the tail of the other (handles +1 prefix), min 7 digits.""" a, b = digits(a), digits(b) n = min(len(a), len(b)) return n >= 7 and a[-n:] == b[-n:] def check_tel(href): """Return list of (level, message) for one tel: href.""" out = [] body = href[4:] if body.startswith("//"): return [("ERROR", 'written as "tel://"; RFC 3966 defines "tel:" with no slashes, so behaviour varies by device')] decoded = unquote(body) number, _, params = decoded.partition(";") if not digits(number): return [("ERROR", "tel: link has no number")] if re.search(r"\s", decoded): out.append(("WARN", "contains spaces; RFC 3966 does not allow spaces in tel: URIs, use - . ( ) or nothing")) if re.search(r"[A-Za-z]", number): out.append(("WARN", "contains letters (keypad words); the tel: format does not support them, use digits")) if not number.strip().startswith("+") and "phone-context=" not in params: out.append(("WARN", 'no "+" country code and no phone-context; fine locally, ambiguous for visitors abroad')) return out def audit(sitemap): urls = sitemap_urls(sitemap) rows, seen = [], defaultdict(set) forms = defaultdict(Counter) for url in urls: status, ctype, body = fetch(url) if status != 200 or "html" not in ctype: rows.append(("ERROR", url, 0, "", f"page not usable (status {status})")) continue p = PhoneParser() p.feed(body) start = len(rows) for ln in p.links: href, text = ln["href"], " ".join(ln["text"].split()) scheme = href.split(":", 1)[0].lower() if scheme != "tel": rows.append(("WARN", url, ln["line"], href, f"{scheme}: is not a standard phone link; use tel:")) continue for level, msg in check_tel(href): rows.append((level, url, ln["line"], href, msg)) num = unquote(href[4:]).partition(";")[0] if len(digits(num)) >= 7: seen[digits(num)[-10:]].add(url) forms[digits(num)[-10:]][href] += 1 for m in PHONE_RE.finditer(text): if digits(num) and not same_number(m.group(0), num): rows.append(("ERROR", url, ln["line"], href, f'link text shows "{m.group(0)}" but the href dials a different number')) for line, shown in p.loose: rows.append(("WARN", url, line, shown, "phone number is plain text, not a tel: link; tap-to-call depends on the device guessing")) rows[start:] = sorted(rows[start:], key=lambda r: (r[2] == 0, r[2])) for key, pages in sorted(seen.items(), key=lambda kv: -len(kv[1])): top = forms[key].most_common(1)[0][0] rows.append(("INFO", f"{len(pages)} of {len(urls)} pages", 0, top, "distinct number found in tel: links")) return urls, rows def main(): ap = argparse.ArgumentParser() ap.add_argument("sitemap") ap.add_argument("--csv", default="") args = ap.parse_args() urls, rows = audit(args.sitemap) for level, page, line, link, msg in rows: where = page + (f" (line {line})" if line else "") print(f"{level:5} {where} {link} {msg}") c = Counter(r[0] for r in rows) print(f"\n{len(urls)} pages checked. {c['ERROR']} errors, {c['WARN']} warnings, {c['INFO']} info.") if args.csv: with open(args.csv, "w", newline="") as f: w = csv.writer(f) w.writerow(["level", "page", "line", "link", "message"]) w.writerows(rows) sys.exit(1 if c["ERROR"] else 0) if __name__ == "__main__": main() Design choices worth explaining:
- One parser pass per page.
PhoneParsercollects every phone-style link (tel:andcallto:) with its text and line number, and every phone-looking number in the visible text that is not inside atel:link. It skipsscript,style,noscriptandtemplate, so numbers inside JSON-LD are not counted as page text. - Digits are compared, not strings.
(503) 555-0142,503.555.0142and+1 503 555 0142count as the same number.same_numbercompares the tail of the two digit strings, so a leading+1does not cause a false mismatch. - Mismatch is an error, spacing is a warning. A link that dials a different number than it shows is wrong for the visitor every time. A space in the
hrefis a format problem that many devices tolerate. - The INFO lines are the part to read twice. They list every number the site links to and how many pages carry it. A site that should have one number but lists two is worth a question to the client.
- Exit code 1 on errors, so a scheduled run can fail when a link is broken.
-
PHONE_REis North American. For other countries, adjust the pattern. Thetel:checks themselves are not country specific.
Run 1: the "before" site
$ python3 serve_fixture.py before & $ python3 phone_audit.py http://localhost:8503/sitemap.xml --csv report_before.csv WARN http://localhost:8503/ (line 4) tel:+1 503 555 0142 contains spaces; RFC 3966 does not allow spaces in tel: URIs, use - . ( ) or nothing WARN http://localhost:8503/ (line 5) 503-555-0142 phone number is plain text, not a tel: link; tap-to-call depends on the device guessing WARN http://localhost:8503/services/ (line 4) tel:+1 503 555 0142 contains spaces; RFC 3966 does not allow spaces in tel: URIs, use - . ( ) or nothing ERROR http://localhost:8503/services/ (line 6) tel://5035550142 written as "tel://"; RFC 3966 defines "tel:" with no slashes, so behaviour varies by device WARN http://localhost:8503/emergency/ (line 4) tel:+1 503 555 0142 contains spaces; RFC 3966 does not allow spaces in tel: URIs, use - . ( ) or nothing ERROR http://localhost:8503/emergency/ (line 5) tel:+15035550142 link text shows "503-555-0198" but the href dials a different number WARN http://localhost:8503/contact/ (line 4) tel:+1 503 555 0142 contains spaces; RFC 3966 does not allow spaces in tel: URIs, use - . ( ) or nothing WARN http://localhost:8503/contact/ (line 5) tel:5035550142;ext=2 no "+" country code and no phone-context; fine locally, ambiguous for visitors abroad WARN http://localhost:8503/contact/ (line 5) (503) 555-0142 phone number is plain text, not a tel: link; tap-to-call depends on the device guessing WARN http://localhost:8503/blog/dog-winter-care/ (line 4) tel:+1 503 555 0142 contains spaces; RFC 3966 does not allow spaces in tel: URIs, use - . ( ) or nothing WARN http://localhost:8503/blog/dog-winter-care/ (line 5) tel:1-800-FLEA-VET contains letters (keypad words); the tel: format does not support them, use digits WARN http://localhost:8503/blog/dog-winter-care/ (line 5) tel:1-800-FLEA-VET no "+" country code and no phone-context; fine locally, ambiguous for visitors abroad WARN http://localhost:8503/blog/dog-winter-care/ (line 5) callto:+15035550142 callto: is not a standard phone link; use tel: INFO 5 of 5 pages tel:+1 503 555 0142 distinct number found in tel: links 5 pages checked. 2 errors, 11 warnings, 1 info. exit 1 (The exit 1 line is the shell printing the script's exit code.)
Reading the output:
- Two errors.
tel://5035550142on the services page is not the form the RFC defines. On the emergency page, the link text promises the after-hours line (503-555-0198) but thehrefdials+15035550142, the main number. A visitor who taps it at 10 pm reaches the wrong line, and the page looks fine. - Eleven warnings. Five are the same header link, repeated once per page because it lives in the shared template. Fix that once and five lines disappear. Two are plain-text numbers on the home and contact pages. The rest are the no-
+extension link, the keypad letters and thecallto:link. - One info line. Only one number is linked anywhere on the site. That is the clue that the after-hours number,
503-555-0198, is not tappable on any page.
On a real site with hundreds of pages, sort the CSV by the link column first. Template problems group together, and you fix them in one place.
The fixes
- Changed the header link to
tel:+15035550142. This cleared five warnings in one edit. - Wrapped the home page nu...


