The Search Console API doesn't only filter with equals and contains. Its filter operators include includingRegex and excludingRegex, both using RE2 syntax (Search Analytics API reference). That one detail lets you automate a review that most people do by hand, one page at a time.

The review in question goes like this: give a page 28 days of data, then find the searches where Google shows it often but people rarely click, plus the long, conversational queries that read like questions. Those are the phrases to work into the page. This post turns that into a script you can run on a schedule.

What the script produces

For each page you care about, two CSVs:

  1. Opportunities: queries with plenty of impressions but few clicks in the latest 28 days.
  2. Questions: long queries (roughly eight words or more) the page appeared for, found with a regex filter.

Plus a small summary comparing the latest 28 days with the previous 28 for each page.

Setup

  1. In Google Cloud, enable the Google Search Console API for a project.
  2. Create a service account and download its JSON key.
  3. Add the service account's email as a user on your Search Console property.
  4. Install the client libraries:
pip install google-api-python-client google-auth pandas 

Define the two windows

from datetime import date, timedelta def window(end, days=28): start = end - timedelta(days=days - 1) return start.isoformat(), end.isoformat() # Leave a few days' gap: the newest Search Console data can be preliminary. END = date.today() - timedelta(days=3) CURRENT = window(END) PREVIOUS = window(END - timedelta(days=28)) 

Two windows of exactly 28 days each means both contain four of every weekday, so day-of-week patterns don't skew the comparison.

Query helper with optional regex

from google.oauth2 import service_account from googleapiclient.discovery import build SITE = "sc-domain:example.com" creds = service_account.Credentials.from_service_account_file( "service-account.json", scopes=["https://www.googleapis.com/auth/webmasters.readonly"], ) service = build("searchconsole", "v1", credentials=creds) def fetch(start, end, dimensions, page=None, query_regex=None): filters = [] if page: filters.append({"dimension": "page", "operator": "equals", "expression": page}) if query_regex: filters.append({"dimension": "query", "operator": "includingRegex", "expression": query_regex}) body = { "startDate": start, "endDate": end, "dimensions": dimensions, "type": "web", "rowLimit": 25000, } if filters: body["dimensionFilterGroups"] = [{"filters": filters}] resp = service.searchanalytics().query(siteUrl=SITE, body=body).execute() return resp.get("rows", []) 

Filters inside one group are combined, so a page filter plus a query regex gives you "this page, these kinds of searches".

Page summary: this 28 days vs the last 28

import pandas as pd PAGES = [ "https://www.example.com/services/seo/", "https://www.example.com/services/geo/", ] def page_totals(page, start, end): rows = fetch(start, end, ["page"], page=page) if not rows: return {"clicks": 0, "impressions": 0, "position": None} r = rows[0] return {"clicks": r["clicks"], "impressions": r["impressions"], "position": round(r["position"], 1)} summary = [] for page in PAGES: prev = page_totals(page, *PREVIOUS) cur = page_totals(page, *CURRENT) summary.append({"page": page, **{f"prev_{k}": v for k, v in prev.items()}, **{f"cur_{k}": v for k, v in cur.items()}}) pd.DataFrame(summary).to_csv("page_summary.csv", index=False) 

Opportunities: shown often, clicked rarely

MIN_IMPRESSIONS = 100 MAX_CLICKS = 1 def to_df(rows): return pd.DataFrame( {"query": r["keys"][0], "clicks": r["clicks"], "impressions": r["impressions"], "ctr": r["ctr"], "position": r["position"]} for r in rows ) for page in PAGES: df = to_df(fetch(*CURRENT, ["query"], page=page)) if df.empty: continue opps = df[(df["impressions"] >= MIN_IMPRESSIONS) & (df["clicks"] <= MAX_CLICKS)] slug = page.rstrip("/").split("/")[-1] opps.sort_values("impressions", ascending=False).to_csv(f"opportunities_{slug}.csv", index=False) 

Tune MIN_IMPRESSIONS to the size of the site. On a small site, 100 impressions in 28 days may already be a strong signal; on a large one, set it higher.

Questions: long, conversational searches

LONG_QUERY = r"(\b\w+\b\s){7,}" # seven words each followed by a space: 8+ words in practice for page in PAGES: df = to_df(fetch(*CURRENT, ["query"], page=page, query_regex=LONG_QUERY)) if df.empty: continue slug = page.rstrip("/").split("/")[-1] df.sort_values("impressions", ascending=False).to_csv(f"questions_{slug}.csv", index=False) 

Long queries are individually rare, but they're written the way people talk, and increasingly the way they ask AI tools. Each one is a candidate heading or FAQ.

Using the output

The script finds candidates. A person still decides what to change:

  • Work the strongest opportunity phrases into the H1, the first paragraph or an FAQ, written naturally.
  • Turn the best question queries into headings, and answer each in the first sentence underneath.
  • Request indexing once after updating, then let another 28 days pass before running the comparison again.

Choosing sensible thresholds

The two numbers in the opportunities filter do most of the work, so it's worth setting them deliberately rather than copying the defaults:

  • Start from the page, not the site. A busy service page and a niche guide need different minimum impressions. One approach is to set MIN_IMPRESSIONS per page, for example at the 75th percentile of that page's query impressions, so you only see its most-shown searches.
  • Allow for small numbers. On low-traffic pages, MAX_CLICKS = 1 can be too strict to return anything useful. Try ctr <= 0.01 instead, which scales with impressions.
  • Cap the list. Five to ten opportunities per page is plenty for one review cycle. More than that and the page changes too much to measure.

Scheduling and sharing the output

A script nobody runs is just a nice idea. Two practical options:

  • A monthly scheduled job. A cron entry, a scheduled CI workflow or a cloud function that runs on the first of each month is enough. Keep the service account key in the scheduler's secret store rather than in the repository.
  • One folder per run. Write each month's CSVs to a dated folder (reports/2026-11/). Diffing two months' questions_*.csv files shows which questions are new, which have gone, and which keep returning.

If the people who edit the pages don't use CSVs, push the summary into a shared spreadsheet instead. The point is that the findings reach someone who can change the page.

Caveats to keep in your report

  • Top rows only. The API returns top rows rather than every row, so treat results as a strong sample, not a census.
  • Anonymised queries. Rare queries can be omitted when you filter or group by query, so some long-tail searches won't appear.
  • Average position needs context. It's averaged across every query a page appeared for. If a page starts appearing for many more searches, the average can fall even while clicks rise.
  • Regex is RE2. Lookaheads and some other advanced features aren't supported, so keep patterns simple.

Where this fits

This is an automated version of a manual process. The full write-up of the manual 28-day method this script automates includes real before-and-after numbers from the pages it was tested on, plus the caveats.

Run it monthly, keep each month's CSVs, and diff them. The interesting signal is rarely one month's numbers. It's which questions keep coming back.

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.