A practical guide for website owners and content marketers to improve site health and retain traffic—no computer science degree required.
If you run a website, blog, or online business, you already know that broken links are the silent killers of SEO.
When a user clicks a link on your site and hits a "404 Not Found" page, two terrible things happen:
- The user bounces. They leave your site, killing your retention metrics.
- Google penalizes you. Search engine crawlers waste their "crawl budget" on dead ends, signaling that your site is unmaintained. Most website owners pay for expensive SEO tools like Ahrefs or Semrush to find these errors. But what if I told you that you could build your own automated SEO crawler in about 15 lines of Python? As a technical writer and content creator, I use Python to automate my daily workflows. Today, I am going to show you how to write a simple script that audits your webpage for broken links.
Why Python for SEO?
You don't need to be a developer to use Python. Think of it as Excel on steroids. By writing a tiny script, we can ask the computer to visit our website, find every single clickable link, and check if it is still alive—a process that would take hours to do manually.
The Python SEO Auditor Script
Here is a simple script using two popular Python libraries: requests (to visit the web pages) and BeautifulSoup (to read the HTML).
import requests
from bs4 import BeautifulSoup
def find_broken_links(url):
print(f"🔍 Scanning URL: {url}\n{'-'*40}")
# 1. Fetch the web page
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
# 2. Find all hyperlinks (<a> tags) on the page
links = soup.find_all('a', href=True)
# 3. Check each link's status
for link in links:
href = link['href']
# We only want to check full web addresses (http/https)
if href.startswith('http'):
try:
# Send a quick "HEAD" request just to check the status
res = requests.head(href, timeout=5)
# HTTP status codes 400 and above indicate errors (like 404)
if res.status_code >= 400:
print(f"❌ Broken Link: {href} (Error: {res.status_code})")
else:
print(f"✅ Healthy Link: {href}")
except requests.RequestException:
print(f"⚠️ Could not reach: {href}")
# Replace this with your own website article URL
target_page = "https://example.com/your-article-here"
find_broken_links(target_page)
How to Run This Without Installing Anything
If you aren't a programmer, looking at code can be intimidating. But you don't even need to install Python on your computer to run this!
- Go to Google Colab (colab.research.google.com) — it is a free tool by Google that lets you run Python directly in your browser.
- Click "New Notebook".
- Paste the code above into the gray cell.
- Change the
"https://example.com/your-article-here"to a link on your own blog. - Click the "Play" button next to the cell. Within seconds, the script will scan your entire article and print out a report of exactly which links are healthy and which ones need to be fixed immediately.
The Business Value of Technical Content
Automating tedious tasks doesn't just save you hours of manual clicking; it actively protects your revenue. By running a simple script like this once a month, you ensure your site remains highly optimized for Google's crawlers, lowering your bounce rate and keeping your search rankings safe.
Coding isn't just for building apps anymore. It is the ultimate leverage for the modern digital entrepreneur.
Top comments (0)