Skip to the content
Start free

Python for SEO

Python for SEO means using the Python programming language to automate search work that is slow by hand, such as checking hundreds of pages for errors, pulling Search Console data, reading server logs and grouping keywords. You do not need to be a developer. A few short scripts can save hours each month, as long as you know what to measure and you treat other people’s websites with care.

What is Python for SEO? #

Python is a free, general-purpose language with a large standard library. For technical SEO it is popular because the jobs are repetitive: fetch a page, read a tag, save a row, repeat 5,000 times. A script does that the same way every time, which makes your checks repeatable. It is a form of SEO automation, not a replacement for judgement.

Which SEO jobs suit Python? #

Job What the script does Wiki word
Status checks Requests every URL in a list and records 200, 301, 404 or 5xx HTTP status code
Redirect audits Follows each hop and flags chains and loops Redirect chain
On-page checks Reads titles, descriptions, canonicals and headings Title tag
Sitemap checks Compares sitemap URLs with what returns 200 XML sitemap
Robots rules Tests whether a bot may fetch each address Robots.txt
Search data Pulls queries and pages from the Search Console API Google Search Console
Log reading Counts which bots fetched which pages Log file analysis
Keyword groups Clusters phrases that share words or results Keyword cluster

How do I start? #

  1. Install Python 3 from python.org and a plain text editor.
  2. Start with the standard library. It already reads web pages, CSV files and JSON.
  3. Keep inputs and outputs as CSV so you can open them anywhere.
  4. Write 1 script for 1 job. Name it after the job.
  5. Run it on 10 URLs first, read the output by hand, then scale up.

A worked example: is this page open to Googlebot? #

Python ships with a robots.txt parser. Its RobotFileParser class reads a robots.txt file, and its can_fetch method returns True when a named user agent may fetch a URL under those rules. This short script checks 3 addresses for Googlebot and for GPTBot:

from urllib.robotparser import RobotFileParser

rp = RobotFileParser()
rp.set_url("https://www.example.com/robots.txt")
rp.read()

pages = ["/", "/basket/", "/blog/winter-boots/"]
for bot in ["Googlebot", "GPTBot"]:
    for p in pages:
        ok = rp.can_fetch(bot, "https://www.example.com" + p)
        print(bot, p, "allowed" if ok else "blocked")

If the output says GPTBot is blocked from the blog, you have learned in seconds what could take an hour to spot by hand. Python’s parser is a good guide, but each search engine reads robots.txt its own way, so confirm important results in the engine’s own tools. See GPTBot and block AI crawlers.

How do I pull Search Console data? #

The API lets you save far more rows than you would ever copy from the screens by hand. Google’s reference for the Search Analytics query method says you send a start date and an end date, choose dimensions such as query, page or date, and can return up to 25,000 rows per request, paging with startRow. Google’s usage limits page lists 1,200 Search Analytics queries a minute per site. The URL Inspection API is allowed 2,000 calls a day per site, and Google says it reports the indexed version of a page, not the live one. Save the data each month and you keep history beyond what the screens show. See URL Inspection and SEO reporting.

Can Python check page speed? #

Yes, through an API. Google’s PageSpeed Insights API guide says the API returns lab data from Lighthouse and real-world data from the Chrome User Experience Report. The same page says Google plans to stop including that real-world data in this API, and points to the CrUX API instead. See Google PageSpeed Insights, Google Lighthouse and Core Web Vitals.

Why does it matter for AI answers? #

AI visibility has new questions that few ready-made tools answer well. Which AI crawlers read your pages? Do they come back? Are they who they say they are? A short script over your server logs can count requests by user agent, and a reverse DNS bot check can test whether a “Googlebot” is real. Together these separate verified bots from impostors using a borrowed name.

Common mistakes #

  • Crawling too fast. Hundreds of requests a second can slow a site or get you blocked. Pause between requests and respect rate limits.
  • Scraping without care. Read a site’s robots.txt and terms before web scraping, and only collect what you need.
  • Trusting the raw HTML only. Some pages build their content with scripts. A simple fetch misses it; see JavaScript SEO.
  • Keys in the code. Keep API keys in a separate settings file, never in a shared script.
  • No sense check. A script that cannot fail proves nothing. Feed it a known broken URL and make sure it reports it.
  • Building pages at scale. Programmatic SEO without unique value can break spam policies.

How to check it #

  1. Before you script it, see if a free tool already does it: our Redirect Checker, Broken Link Checker, Meta Tag Checker, Sitemap Checker and Robots.txt Checker are live.
  2. Pull a URL list for your script with the Sitemap URL Extractor.
  3. Test patterns with the Regex Tester, and tidy outputs with the JSON Formatter or CSV to JSON Converter.
  4. Check bot visits with the AI Crawler Log Analyser and Verify AI Bot. Group exported keywords with Keyword Clusters.
  5. In URSY Pro, the Log file analyser (Pro) and Search Console forever (Pro) will do these jobs without code. See also Search Console history.

Questions #

Do I need Python to do SEO? #

No. Most small sites never need it. It helps once you have hundreds of pages or want data the screens do not keep.

Is Python better than spreadsheets? #

For 50 rows a spreadsheet is fine. For 50,000 rows, or a job you repeat weekly, a script is faster and makes fewer slips.

Can AI write the scripts for me? #

Often, yes. Read the code, test it on a few URLs and check the output before you trust it.

Sources #

Updated 24 November 2026 by URSY.

Cite this page: Python for SEO. URSY. Updated 24 November 2026. https://ursy.com/wiki/python-for-seo/ · Section links

Tools for this

  • LiveHreflang Checker + Generatorlanguage versions wired both ways, or the tags written for youRun the check →
  • LiveAI Readiness Checkeris your site ready for ChatGPT, Gemini, Claude? Score + fixesRun the check →
  • LiveMarkdown Version Checkerdoes your page have a clean .md copy for AI?Run the check →
  • LiveSEO Checkerone page scored + fixesRun the check →
  • LiveMeta Tag CheckerRun the check →
  • LiveGoogle Snippet Previewtitle and description length in pixels (in browser)Run the check →
  • ProImage SEO auditAlt text, sizes, formats, image sitemapsIn URSY Pro →
  • ProBrand facts (Truth Spine)Your official facts, each with proof, for AI to readIn URSY Pro →
  • ProMarkdown copy coverageWhich pages have a clean .md copy for AIIn URSY Pro →

All 871 wiki entries, A to Z →