---
title: "Python for SEO"
description: "Python for SEO means using short scripts to check pages, pull Search Console data and read logs. Which jobs suit it, a worked example and safe habits."
url: https://ursy.com/wiki/python-for-seo/
updated: 2026-11-24T23:41:40+00:00
publisher: URSY (https://ursy.com/)
cite: Name URSY and link https://ursy.com/wiki/python-for-seo/
---

# Python for SEO

> Python for SEO means using short scripts to check pages, pull Search Console data and read logs. Which jobs suit it, a worked example and safe habits.

**Python for [SEO](https://ursy.com/wiki/seo-search-engine-optimisation/) 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](https://ursy.com/wiki/keyword/).** 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? {#what-is-python-for-seo}

Python is a free, general-purpose language with a large standard library. For [technical SEO](https://ursy.com/wiki/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](https://ursy.com/wiki/seo-automation/), not a replacement for judgement.

## Which SEO jobs suit Python? {#which-seo-jobs-suit-python}

| Job | What the script does | Wiki word |
| --- | --- | --- |
| Status checks | Requests every [URL](https://ursy.com/wiki/url/) in a list and records 200, 301, 404 or 5xx | [HTTP status code](https://ursy.com/wiki/http-status-code/) |
| [Redirect](https://ursy.com/wiki/redirect/) audits | Follows each hop and flags chains and loops | [Redirect chain](https://ursy.com/wiki/redirect-chain/) |
| On-page checks | Reads titles, descriptions, canonicals and headings | [Title tag](https://ursy.com/wiki/title-tag/) |
| Sitemap checks | Compares sitemap URLs with what returns 200 | [XML sitemap](https://ursy.com/wiki/xml-sitemap/) |
| Robots rules | Tests whether a [bot](https://ursy.com/wiki/bot-web-robot/) may fetch each address | [Robots.txt](https://ursy.com/wiki/robots-txt/) |
| Search data | Pulls queries and pages from the Search Console API | [Google Search Console](https://ursy.com/wiki/google-search-console/) |
| Log reading | Counts which bots fetched which pages | [Log file analysis](https://ursy.com/wiki/log-file-analysis/) |
| Keyword groups | Clusters phrases that share words or results | [Keyword cluster](https://ursy.com/wiki/keyword-cluster/) |

## How do I start? {#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? {#a-worked-example-is-this-page-open-to-googlebot}

Python ships with a [robots.txt parser](https://docs.python.org/3/library/urllib.robotparser.html). 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](https://ursy.com/wiki/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](https://ursy.com/wiki/search-engine/) reads robots.txt its own way, so confirm important results in the engine’s own tools. See [GPTBot](https://ursy.com/wiki/gptbot/) and [block AI crawlers](https://ursy.com/wiki/block-ai-crawlers/).

## How do I pull Search Console data? {#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](https://ursy.com/wiki/google/)’s reference for the [Search Analytics query method](https://developers.google.com/webmaster-tools/v1/searchanalytics/query) 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](https://developers.google.com/webmaster-tools/limits) lists 1,200 Search Analytics queries a minute per site. The [URL Inspection API](https://developers.google.com/webmaster-tools/v1/urlInspection.index/inspect) 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](https://ursy.com/wiki/url-inspection/) and [SEO reporting](https://ursy.com/wiki/seo-reporting/).

## Can Python check page speed? {#can-python-check-page-speed}

Yes, through an API. Google’s [PageSpeed Insights API guide](https://developers.google.com/speed/docs/insights/v5/get-started) says the API returns lab data from Lighthouse and real-world data from the Chrome [User Experience](https://ursy.com/wiki/user-experience-ux/) 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](https://ursy.com/wiki/google-pagespeed-insights/), [Google Lighthouse](https://ursy.com/wiki/google-lighthouse/) and [Core Web Vitals](https://ursy.com/wiki/core-web-vitals/).

## Why does it matter for AI answers? {#why-does-it-matter-for-ai-answers}

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

## Common mistakes {#common-mistakes}

- **[Crawling](https://ursy.com/wiki/crawling/) too fast.**  Hundreds of requests a second can slow a site or get you blocked. Pause between requests and respect [rate limits](https://ursy.com/wiki/rate-limiting/).
- **Scraping without care.**  Read a site’s robots.txt and terms before [web scraping](https://ursy.com/wiki/web-scraping/), and only collect what you need.
- **Trusting the raw [HTML](https://ursy.com/wiki/html/) only.**  Some pages build their content with scripts. A simple fetch misses it; see [JavaScript SEO](https://ursy.com/wiki/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](https://ursy.com/wiki/programmatic-seo/) without unique value can break spam policies.

## How to check it {#how-to-check-it}

1. Before you script it, see if a free tool already does it: our [Redirect Checker](https://ursy.com/redirect-checker/), [Broken Link Checker](https://ursy.com/broken-link-checker/), [Meta Tag Checker](https://ursy.com/meta-tag-checker/), [Sitemap Checker](https://ursy.com/sitemap-checker/) and [Robots.txt Checker](https://ursy.com/robots-txt-checker/) are live.
2. Pull a URL list for your script with the [Sitemap URL Extractor](https://ursy.com/webmaster-tools/sitemap-url-extractor/).
3. Test patterns with the [Regex Tester](https://ursy.com/webmaster-tools/regex-tester/), and tidy outputs with the [JSON Formatter](https://ursy.com/webmaster-tools/json-formatter/) or [CSV to JSON Converter](https://ursy.com/webmaster-tools/csv-to-json-converter/).
4. Check [bot visits](https://ursy.com/wiki/bot-visit/) with the [AI Crawler Log Analyser](https://ursy.com/ai-crawler-log-analyzer/) and [Verify AI Bot](https://ursy.com/verify-ai-bot/). Group exported keywords with [Keyword Clusters](https://ursy.com/keyword-clusters/).
5. In URSY Pro, the [Log file analyser](https://ursy.com/pro/log-file-analyser/) (Pro) and [Search Console forever](https://ursy.com/pro/search-console-forever/) (Pro) will do these jobs without code. See also [Search Console history](https://ursy.com/search-console-history/).

## Questions {#questions}

### Do I need Python to do SEO? {#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? {#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? {#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.

## Related words {#related-words}

- [SEO automation](https://ursy.com/wiki/seo-automation/)
- [Log file analysis](https://ursy.com/wiki/log-file-analysis/)
- [Web scraping](https://ursy.com/wiki/web-scraping/)
- [Technical SEO](https://ursy.com/wiki/technical-seo/)
- [Robots.txt](https://ursy.com/wiki/robots-txt/)

## Sources {#sources}

- [Python documentation: urllib.robotparser](https://docs.python.org/3/library/urllib.robotparser.html), checked 24 November 2026
- [Google Search Console API: Search Analytics query](https://developers.google.com/webmaster-tools/v1/searchanalytics/query), checked 24 November 2026
- [Google Search Console API: Usage limits](https://developers.google.com/webmaster-tools/limits), checked 24 November 2026
- [Google Search Console API: URL Inspection index inspect](https://developers.google.com/webmaster-tools/v1/urlInspection.index/inspect), checked 24 November 2026
- [Google: Get started with the PageSpeed Insights API](https://developers.google.com/speed/docs/insights/v5/get-started), checked 24 November 2026

*Updated 24 November 2026 by URSY.*
