環境を準備する
Python 3と標準ライブラリを使用します。 作成する APIキー 口座が利用可能なクレジットを必ず確認してください。 もしこれが最初のリクエストの場合、 APIクイックスタート.
# Replace YOUR_API_KEY near the top of the code below.下のスクリプトは、検索対象の openai 米国の結果と英語のインターフェイスを使用して、返されたオーガニックリンクをCSVファイルに書きます。
検索結果をフェッチして保存する
スクリプトをスクリプトとして保存する search.py. リアルタイムリクエストを1件提出する source: "google_search" そして読みます organic 最初の結果から配列。
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.py営業拠点 google-results.csv スプレッドシートに、またはアプリケーションにロードします。 エクスポートされた列は、位置、タイトル、URL、スニペットです。 PythonのCSVライターは、結果のテキスト内のコンマとラインブレイクの引用を処理します。
API 応答を理解する
この記録された応答は、OpenAI検索で返された構造を示しています。 スクリプトは、アプリケーションが必要とする場合は、API応答に、有機的なリンクをエクスポートします。
{
"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"
}この num 結果のカウントを引数としてリクエストします。 Googleは、多くのオーガニックリンクが返されるという保証はありません。 スクリプトが保存されますが、多くの結果が返されます。
検索を変更
変更点 query あなたのトピックのために、, params.gl 国と国 params.hl インターフェイス言語のため。 利用条件 params.page 別のページリクエストに、各ページは別々のAPIコールです。
結果を比較するには、クエリ、領域、および各行のコレクション時間を格納します。 API は検索スナップショットを返します。 履歴比較は、保存したスナップショットから来ます。