Skip to content

joehall/gsc_querypage_exporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Google Search Console Query + Page Exporter

A Google Colab script that connects to the Google Search Console API and exports all queries and their ranking pages into CSV files — including clicks, impressions, CTR, and position.


What It Does

  • Authenticates with Google via OAuth (no service account or owner access required)
  • Pulls up to 16 months of Search Console data
  • Exports every query + page combination with the following metrics:
    • Query
    • Page URL
    • Clicks
    • Impressions
    • CTR (%)
    • Average Position
  • Saves data in batches of 10,000 rows per CSV file to avoid timeouts
  • Auto-downloads all CSV files to your computer when complete

Requirements

  • A Google account with access to a Search Console property (owner, full, or restricted access)
  • A Google Cloud project with the Search Console API enabled
  • OAuth 2.0 credentials (Desktop App type)

Setup Guide

Step 1 — Enable the Search Console API

  1. Go to Google Cloud Console
  2. Select or create a project
  3. Navigate to APIs & Services → Enabled APIs & Services
  4. Search for Google Search Console API and click Enable

Step 2 — Create OAuth Credentials

  1. In Google Cloud Console, go to APIs & Services → OAuth consent screen
    • Select External and click Create
    • Fill in App name, User support email, and Developer contact email
    • Click Save and Continue through all remaining screens
  2. Go to APIs & Services → Credentials
    • Click + Create Credentials → OAuth Client ID
    • Choose Desktop App as the application type
    • Give it a name (e.g. GSC Colab Export) and click Create
  3. Copy your Client ID and Client Secret from the popup

Step 3 — Configure the Script

Open the script in Google Colab and update the following fields:

# Step 3 — paste your credentials here
CLIENT_CONFIG = {
    "installed": {
        "client_id":     "YOUR_CLIENT_ID.apps.googleusercontent.com",  # ← replace
        "client_secret": "YOUR_CLIENT_SECRET",                          # ← replace
        ...
    }
}
# Step 6 — set your Search Console property URL
SITE_URL = "https://www.example.com/"   # ← replace with your exact GSC property URL

Tip: Run Step 5 first — it prints all GSC properties your account can access so you can copy the exact URL.


Step 4 — Authenticate

When you run Step 4, the script will print an authorization URL.

  1. Open the URL in your browser
  2. Sign in with the Google account that has Search Console access
  3. Click Allow on the permissions screen
  4. Copy the authorization code and paste it back into the Colab input box

Step 5 — Run the Script

Run all remaining cells. The script will:

  1. Print all accessible Search Console properties
  2. Begin fetching data in batches of 2,500 rows per API request
  3. Save a new CSV file every 10,000 rows
  4. Auto-download all CSV files when complete

Note: Large sites with many queries can take a long time to export. The script handles timeouts automatically with retry logic, backing off between attempts.


Recovering Files If the Script Is Interrupted

If the script times out or you stop it manually, any CSV files already saved can still be downloaded. Run this in a new Colab cell:

import os
from google.colab import files

saved = sorted([f for f in os.listdir(".") if f.startswith("search_console_export")])

print(f"Found {len(saved)} file(s):")
for f in saved:
    size = os.path.getsize(f) / 1024
    print(f"  {f}  ({size:,.0f} KB)")

for f in saved:
    files.download(f)

⚠️ Files are lost if the Colab runtime resets. Download them before closing your session.


Configuration Options

Variable Default Description
API_BATCH_SIZE 2500 Rows fetched per API request. Lower this if you experience timeouts.
CSV_BATCH_SIZE 10000 Rows per CSV file
MAX_RETRIES 5 Number of retry attempts on timeout
RETRY_DELAY 15 Base seconds to wait between retries (increases with each attempt)
REQUEST_TIMEOUT 90 Seconds before a request times out

Output

CSV files are named sequentially:

search_console_export_part1.csv
search_console_export_part2.csv
...

Each file contains the following columns:

Column Description
Query The search query
Page The ranking page URL
Clicks Total clicks in the date range
Impressions Total impressions in the date range
CTR Click-through rate (%)
Position Average ranking position

Notes

  • The Search Console API returns data with a ~3 day lag, so the export ends 3 days before today
  • The API only returns the top 1,000 rows per unique query/page combination
  • Data covers the last 16 months (the maximum Search Console retains)
  • This script uses OAuth user authentication — no service account or property owner access is required

License

GPL v3 - https://www.gnu.org/licenses/gpl-3.0.en.html

About

No description, website, or topics provided.

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages