SerpBase
Back to Blog

Export Google Search Results to CSV with Python

A 30-line Python script that turns a keyword list into a CSV of Google results: rank, title, link and snippet. Tested on three keywords, with the pitfalls we hit.

November 28, 2026
By SerpBase Team3 min read

Short answer: loop over your keywords, call /google/search for each, and write the organic list to a CSV file with Python's csv module. About 30 lines, no scraping library, and the file opens in Excel or Google Sheets.

One request

curl -X POST 'https://api.serpbase.dev/google/search' \
  -H 'Content-Type: application/json' \
  -H 'X-API-Key: YOUR_API_KEY' \
  -d '{"q":"standing desk","gl":"us","hl":"en"}'

Each entry in organic has rank, title, link and usually snippet. Those four become the columns.

Python: keywords in, CSV out

import csv, time, requests

API = "https://api.serpbase.dev"
HEADERS = {"X-API-Key": "YOUR_API_KEY"}
KEYWORDS = ["standing desk", "ergonomic chair", "monitor arm"]

def post(path, body):
    return requests.post(API + path, headers=HEADERS, json=body, timeout=60).json()

def real_links(organic):
    """Swap Google wrapper links for the real page addresses (free call)."""
    wrapped = [o["link"] for o in organic if "google.com/goto" in o["link"]]
    if not wrapped:
        return {}
    time.sleep(1)
    fixed = post("/google/resolve", {"links": wrapped})
    return {x["link"]: x["url"] for x in fixed.get("resolved_links", [])
            if x.get("reason") == "resolved"}

with open("serp.csv", "w", newline="", encoding="utf-8") as f:
    w = csv.writer(f)
    w.writerow(["keyword", "rank", "title", "link", "snippet"])
    for kw in KEYWORDS:
        r = post("/google/search", {"q": kw, "gl": "us", "hl": "en"})
        if r["status"] != 0:
            print(kw, "failed:", r.get("error"))
            continue
        organic = r.get("organic", [])
        real = real_links(organic)
        for o in organic:
            w.writerow([kw, o["rank"], o["title"],
                        real.get(o["link"], o["link"]), o.get("snippet", "")])
        print(kw, len(organic), "rows")
        time.sleep(1)

What we got

We ran this script on 28 November 2026.

KeywordOrganic rowsWrapper linksResolved
standing desk854
ergonomic chair964
monitor arm633

The file had 23 result rows plus the header. Three rows still carried a Google wrapper link. The run cost 3 credits: one per search, nothing for the link calls.

The first lines of an earlier run of the same keywords:

keyword,rank,title,link,snippet
standing desk,1,Height Adjustable Electric Standing Desks | Sit-Stand,https://www.vari.com/desks-and-tables/standing-desks/?srsltid=...,Shop standi...
standing desk,2,UPLIFT V3 Standing Desk,https://www.upliftdesk.com/2-leg-standing-desk/?srsltid=...,"The UPLIFT V3 Desk redefines standing desks wi..."
standing desk,3,Standing Desk,https://www.amazon.com/standing-desk/s?k=standing+desk,"One-Piece Standing Desk, Electric Adjustable with 4 Memory Presets, ..."

Things that trip people up

  • Let the csv module do the quoting. Titles and snippets contain commas and quotation marks. Joining fields with "," yourself breaks the file on rows like the second one below the header above.
  • Open the file with newline="" and encoding="utf-8". Without the first you get blank lines between rows on Windows. If Excel shows garbled accents, use encoding="utf-8-sig".
  • Some links are Google wrappers. Lower results can come back as google.com/goto links. The script sends those to the free link resolver and keeps the wrapper when one is not resolved (3 of 14 in our run). Resolve the leftovers in a second pass.
  • Shop links carry a srsltid tracking parameter. Two of the three rows above have one. Strip it before you compare links between runs, or the same page will look like a new one every day.
  • Row counts differ by keyword. We got 8, 9 and 6. Google fills part of the page with other modules, so do not assume ten.
  • rank is the place among organic results only. The AI overview, People Also Ask and the local pack are separate fields and not in this file. Use position if you want where the result sat on the page.
  • Check status, not the HTTP code. Every answer is HTTP 200; a failed search has a non-zero status and is not charged.

Going further

Cost and limits

One search is 1 credit, so a 1,000-keyword export costs 1,000 credits. Credits cost $0.25–$0.50 per 1,000 depending on the plan; failed requests are not charged, and new accounts get 500 free credits without a card.