Stop deploys from breaking SEO: a pre-release smoke test in Python
An SEO smoke test, in this context, is a short automated check that runs after a deploy and answers one question: can search engines still reach and index the pages that matter?
It isn't an audit. It doesn't care about alt text or title length. It looks for the handful of mistakes that can quietly remove a site from search results, and fails the build if it finds one.
Those mistakes are surprisingly common, and they almost always arrive with a release: a staging noindex that made it to production, a Disallow: / copied from a test environment, canonical tags still pointing at a staging domain, or an important URL that suddenly redirects. None of them break the site for users, so nobody notices until traffic drops.
This post builds a small Python script that catches all four. It uses requests and the standard library, reads a list of key pages, and exits with a non-zero code if anything looks wrong.
What it checks
For every URL in a short list of key pages:
- Status code. The page must return 200 directly, not a redirect or an error.
- robots.txt. Googlebot must be allowed to fetch the URL.
- noindex. Neither a
<meta name="robots">tag nor anX-Robots-Tagheader may containnoindex. - Title. The page must have a non-empty
<title>. - Canonical. The page must have a canonical tag, and it must point at the production host.
Google's documentation explains why the robots.txt and noindex checks belong together: robots.txt is "not a mechanism for keeping a web page out of Google", and for noindex to work, the page "must not be blocked by a robots.txt file" (Google Search Central). A deploy can get either one wrong independently.
Setup
pip install requests
Create a key_pages.txt file with one path per line. Keep it short and focused: the homepage, your main service or category pages, and one example of each important template.
/
/services/
/services/web-design/
/blog/
/contact/
The script
import sys
from html.parser import HTMLParser
from urllib.parse import urljoin, urlparse
from urllib.robotparser import RobotFileParser
import requests
HEADERS = {"User-Agent": "seo-smoke-test/1.0"}
class HeadParser(HTMLParser):
def __init__(self):
super().__init__()
self.title = ""
self.canonical = None
self.robots = ""
self._in_title = False
def handle_starttag(self, tag, attrs):
a = {k.lower(): (v or "") for k, v in attrs}
if tag == "title":
self._in_title = True
elif tag == "link" and "canonical" in a.get("rel", "").lower().split():
self.canonical = a.get("href")
elif tag == "meta" and a.get("name", "").lower() in ("robots", "googlebot"):
self.robots += " " + a.get("content", "").lower()
def handle_endtag(self, tag):
if tag == "title":
self._in_title = False
def handle_data(self, data):
if self._in_title:
self.title += data.strip()
def check_url(url, robots, expected_host):
problems = []
r = requests.get(url, headers=HEADERS, allow_redirects=False, timeout=20)
if r.status_code != 200:
problems.append(f"status {r.status_code}")
return problems
if "noindex" in r.headers.get("X-Robots-Tag", "").lower():
problems.append("X-Robots-Tag: noindex")
if not robots.can_fetch("Googlebot", url):
problems.append("blocked by robots.txt")
page = HeadParser()
page.feed(r.text)
if "noindex" in page.robots:
problems.append("meta robots noindex")
if not page.title:
problems.append("missing <title>")
if not page.canonical:
problems.append("missing canonical")
else:
canonical = urljoin(url, page.canonical)
if urlparse(canonical).netloc != expected_host:
problems.append(f"canonical points to {urlparse(canonical).netloc}")
return problems
def main(base, paths):
expected_host = urlparse(base).netloc
robots = RobotFileParser()
rt = requests.get(urljoin(base, "/robots.txt"), headers=HEADERS, timeout=20)
robots.parse(rt.text.splitlines() if rt.status_code == 200 else [])
failures = 0
for path in paths:
url = urljoin(base, path)
problems = check_url(url, robots, expected_host)
status = "OK" if not problems else "FAIL"
print(f"{status} {url} {'; '.join(problems)}")
failures += bool(problems)
print(f"\n{len(paths) - failures}/{len(paths)} key pages passed")
sys.exit(1 if failures else 0)
if __name__ == "__main__":
base_url = sys.argv[1]
key_paths = [line.strip() for line in open("key_pages.txt") if line.strip()]
main(base_url, key_paths)
How it works
HeadParser uses the standard library's HTMLParser to pull three things out of the raw HTML: the title, the canonical link and the contents of any robots meta tags. It handles rel values with several tokens and collects both robots and googlebot meta tags, since either can carry noindex.
check_url fetches each page with allow_redirects=False. That's deliberate: if a key page starts redirecting, you want to know, even if the redirect is intentional. It then checks the response header, robots.txt permission and the parsed HTML.
main fetches robots.txt once with requests and hands the lines to RobotFileParser. This matters more than it looks. If you let RobotFileParser.read() fetch the file itself, it uses Python's default user agent, and some servers or CDNs block that. A 401 or 403 response makes the parser treat the whole site as disallowed, which produces confusing false failures. Fetching it yourself, with your own user agent, avoids that.
The canonical check compares hosts rather than full URLs. That catches the classic staging leak, a canonical pointing at staging.example.com, without failing pages whose canonical deliberately differs, such as a filtered URL pointing at its parent category.
Running it
python seo_smoke.py https://www.example.com
Output looks like this:
OK https://www.example.com/
OK https://www.example.com/services/
FAIL https://www.example.com/services/web-design/ meta robots noindex
OK https://www.example.com/blog/
FAIL https://www.example.com/contact/ status 301
3/5 key pages passed
The exit code is 1 whenever any page fails, so CI treats it as a failed step.
Running it in CI
Run the check straight after your deploy job, against the live URL. In GitHub Actions, that might look like this:
name: SEO smoke test
on:
workflow_dispatch:
schedule:
- cron: "0 6 * * *"
jobs:
smoke:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install requests
- run: python seo_smoke.py https://www.example.com
The schedule adds a daily safety net for changes made outside your pipeline, such as a CMS setting or a plugin update. In your real deploy workflow, add the same steps as a job with needs: deploy so it runs as soon as the release is live.
When the check fails
A red build after a deploy can feel alarming, so it helps to agree in advance what happens next. A simple order of work:
- Read the failure reason. The script prints exactly what it found: a status code, a noindex, a robots.txt block or a canonical host.
- Confirm it in a browser. Open the URL, view the source and check the response headers. Make sure it isn't a temporary outage or a bot challenge.
- Decide whether to roll back. A noindex or robots.txt block on key pages is usually worth a rollback or an immediate hotfix. A single redirected URL may be fine if it was intended.
- Fix the cause, not just the symptom. If a staging setting leaked, find out why the environment configuration allowed it, and fix that too.
- Re-run the check. Only close the incident when the script passes against the live site.
It's also worth telling whoever owns SEO in the business whenever the check fails, even if the fix was quick. A pattern of near-misses is useful information.
Why a short list beats a full crawl here
It's tempting to point the script at your whole sitemap. Resist it, at least for the deploy step. A full crawl takes longer, hits your servers harder and produces noise that people learn to ignore. A short list of representative URLs runs in seconds, and if it fails, the failure almost certainly matters. Run full crawls on a separate schedule, where speed isn't critical.
Things to watch out for
- JavaScript-rendered tags. The script reads the raw HTML response. If your canonical or robots tags are injected by client-side JavaScript, the script won't see them. That's worth knowing anyway, because search engines may not reliably see them either.
- Bot protection. Some CDNs challenge unknown user agents. Allow-list your CI runner or the script's user agent, or you'll get 403 failures that aren't SEO problems.
- Intentional redirects. If a key page is meant to redirect, update
key_pages.txtto the final URL rather than weakening the check. - Keep the list short. This is a smoke test. Ten to thirty URLs that represent your templates is plenty. Full crawls belong in a separate, slower job.
Extending it
Useful additions, depending on your site:
- Check that
/sitemap.xmlreturns 200 and contains your key URLs. - Check hreflang tags on international templates.
- Flag pages where the title or canonical changed since the last run by storing results as JSON.
- Post failures to Slack or Teams so the right people see them immediately.
Where this fits
A smoke test catches release accidents. It doesn't replace a proper technical review of architecture, rendering or performance. For the wider picture, this is a good companion read: a complete guide to technical SEO for business websites.
Add the script to your next deploy, list your ten most important pages, and you'll find out about the next noindex accident in minutes rather than weeks.
This article was drafted with AI assistance and reviewed by the Prox Digital Agency team. Test the code in your own environment before relying on it.
Comments
No comments yet. Start the discussion.