DEV Community

Lucy Green
Lucy Green

Posted on

Automating SEO Audits with Python (and Taking Them Further)

If you've ever managed more than a handful of websites, you've probably spent far too much time checking the same things over and over again:

  • Is the title tag missing?
  • Does every page have a meta description?
  • Are images missing alt attributes?
  • Is there exactly one <h1>?
  • Are canonical tags configured correctly?

Doing this manually gets old fast.

I wanted a lightweight way to catch the obvious issues before running a full SEO audit, so I put together a simple Python script that scans a page and reports common on-page problems.

Install the Dependencies

pip install requests beautifulsoup4
Enter fullscreen mode Exit fullscreen mode

Basic SEO Audit Script

import requests
from bs4 import BeautifulSoup

def audit_page(url):
    response = requests.get(url, timeout=10)
    soup = BeautifulSoup(response.text, "html.parser")

    issues = []

    title = soup.title.string.strip() if soup.title and soup.title.string else ""
    if not title:
        issues.append("Missing title tag")
    elif len(title) > 60:
        issues.append("Title exceeds recommended length")

    description = soup.find("meta", attrs={"name": "description"})
    if not description or not description.get("content"):
        issues.append("Missing meta description")

    h1_tags = soup.find_all("h1")
    if len(h1_tags) == 0:
        issues.append("Missing H1")
    elif len(h1_tags) > 1:
        issues.append("Multiple H1 tags detected")

    images = soup.find_all("img")
    missing_alt = [img.get("src") for img in images if not img.get("alt")]

    if missing_alt:
        issues.append(f"{len(missing_alt)} images missing alt text")

    canonical = soup.find("link", rel="canonical")
    if not canonical:
        issues.append("Missing canonical tag")

    return issues

url = "https://example.com"

for issue in audit_page(url):
    print("-", issue)
Enter fullscreen mode Exit fullscreen mode

For quick technical checks, this script works surprisingly well.

But after using it for client projects, I realized something important:

An on-page audit is only one piece of the puzzle.

SEO Doesn't Stop at HTML

Even when every page has perfect metadata, rankings can still suffer because of:

  • Weak backlink profiles
  • Poor keyword targeting
  • Slow Core Web Vitals
  • Indexing issues
  • Broken internal links
  • Missing structured data
  • Competitor content gaps

Checking all of those manually quickly becomes overwhelming.

Extending the Workflow

Instead of writing separate scripts for every SEO task, I now use this script as the first validation step and then follow it with a more comprehensive audit using SERPSpur.

It gives me additional insights such as:

  • On-page SEO analysis
  • Backlink reports
  • Keyword research
  • Competitor comparisons
  • Domain authority metrics
  • Rank tracking
  • Technical SEO diagnostics

That means I can identify both HTML-level issues and broader SEO problems from a single workflow.

Ideas for Improvements

If you're extending this script, here are a few useful additions:

  • Validate Open Graph tags
  • Check Twitter Card metadata
  • Detect broken internal links
  • Verify structured data (JSON-LD)
  • Audit robots meta directives
  • Measure page response time
  • Detect duplicate meta descriptions
  • Export results as CSV
  • Crawl an entire sitemap
  • Generate HTML reports

Final Thoughts

Automation won't replace a proper SEO strategy, but it can eliminate a lot of repetitive work.

A simple Python script is perfect for catching common on-page issues before they become bigger problems. Pairing it with a comprehensive SEO platform lets you move beyond HTML validation and understand how your site performs in search.

Whether you're maintaining your own projects or auditing client websites, combining lightweight automation with a full SEO toolkit can save hours every week.

If you're looking for an all-in-one SEO platform to complement your own scripts, take a look at SERPSpur: https://serpspur.com

Top comments (2)

Collapse
 
micheljee profile image
Michel Jee

Great insights! I've found that building in public not only helps with accountability but also creates a natural feedback loop that improves the end product.

Collapse
 
burhanchaudhry profile image
Burhan

Interesting take. Have you considered how this approach scales when working in a larger team with stricter deadlines?