Prepare your environment
You will use Python 3 and its standard library. Create an API key and make sure your account has available credits. If this is your first request, see the API quickstart.
# Replace YOUR_API_KEY near the top of the code below.The script below searches for openai using US results and an English interface, then writes the returned organic links to a CSV file.
Fetch and save the search results
Save the script as search.py. It submits one realtime request with source: "google_search" and reads the organic array from the first result.
import csv
import json
import os
import urllib.request
base_url = "https://data.flashdata.dev"
api_key = "YOUR_API_KEY"
request = urllib.request.Request(
base_url + "/v1/queries/realtime",
data=json.dumps({
"source": "google_search",
"query": "openai",
"params": {"gl": "us", "hl": "en", "num": 10},
}).encode("utf-8"),
headers={
"X-API-Key": api_key,
"Content-Type": "application/json",
},
method="POST",
)
with urllib.request.urlopen(request, timeout=60) as response:
payload = json.load(response)
if payload.get("status") != "done":
raise RuntimeError(payload.get("message", "Search did not complete"))
results = payload["results"][0].get("organic", [])
with open("google-results.csv", "w", newline="", encoding="utf-8") as output:
writer = csv.DictWriter(output, fieldnames=["position", "title", "url", "snippet"])
writer.writeheader()
for result in results:
writer.writerow({
"position": result.get("position", ""),
"title": result.get("title", ""),
"url": result.get("link", ""),
"snippet": result.get("snippet", ""),
})
print(f"Saved {len(results)} results to google-results.csv")
python3 search.pyOpen google-results.csv in a spreadsheet or load it into your application. The exported columns are position, title, URL and snippet. Python’s CSV writer handles quoting for commas and line breaks inside result text.
Understand the API response
This recorded response shows the structure returned for an OpenAI search. The script exports organic links; other available sections remain in the API response if your application needs them.
{
"source": "google_search",
"status": "done",
"results": [
{
"searchParameters": {
"q": "openai",
"gl": "us",
"hl": "en",
"type": "search",
"num": 10,
"page": 1,
"engine": "google"
},
"organic": [
{
"title": "OpenAI | Research & Deployment",
"link": "https://openai.com/",
"snippet": "We believe our research will eventually lead to artificial general intelligence, a system that can solve human-level problems.",
"position": 1
},
{
"title": "OpenAI",
"link": "https://en.wikipedia.org/wiki/OpenAI",
"snippet": "OpenAI is an American artificial intelligence (AI) public benefit corporation (PBC) headquartered in San Francisco. It develops proprietary generative AI models ...",
"position": 2
},
{
"title": "OpenAI",
"link": "https://x.com/OpenAI",
"snippet": "OpenAI's mission is to ensure that artificial general intelligence benefits all of humanity. can develop research, build financial models, and create ...",
"position": 3
},
{
"title": "OpenAI",
"link": "https://www.linkedin.com/company/openai",
"snippet": "OpenAI is an AI research and deployment company dedicated to ensuring that general-purpose artificial intelligence benefits all of humanity.",
"position": 4
},
{
"title": "r/OpenAI",
"link": "https://www.reddit.com/r/OpenAI/",
"snippet": "OpenAI is an AI research and deployment company. OpenAI's mission is to create safe and powerful AI that benefits all of humanity. OpenAI's ...",
"position": 5
}
],
"peopleAlsoAsk": [
{
"question": "Is OpenAI created by Elon Musk?"
},
{
"question": "Why are people leaving ChatGPT?"
},
{
"question": "Is OpenAI the same as ChatGPT?"
},
{
"question": "Why is OpenAI in trouble?"
}
],
"relatedSearches": [
{
"query": "OpenAI login"
},
{
"query": "OpenAI chat"
},
{
"query": "OpenAI ChatGPT"
},
{
"query": "OpenAI - wikipedia"
},
{
"query": "OpenAI API"
},
{
"query": "OpenAI app"
},
{
"query": "OpenAI download"
},
{
"query": "OpenAI video"
}
]
}
],
"usage": {
"credits": 0.02
},
"created_at": "2026-09-16T07:41:40.043Z"
}The num parameter requests a result count. It does not guarantee that Google will return that many organic links. The script saves however many results are returned.
Change the search
Change query for your topic, params.gl for the country and params.hl for the interface language. Use params.page to request another page; each page is a separate API call.
To compare results over time, store the query, region and collection time alongside each row. The API returns a search snapshot; historical comparisons come from the snapshots you save.