Googleには貴重なデータが含まれています -- organic results, knowledge graph, People Also Ask, AI overviewなど。このデータを直接スクレイピングするには、アンチボット検出、CAPTCHA、IPローテーション、そして頻繁に壊れるセレクタに対処する必要があります。Scavio APIはこれらすべてを処理し、単一のPOSTリクエストでクリーンで構造化されたJSONを返します。
このチュートリアルでは、PythonとScavio APIを使ってGoogleをスクレイピングする方法を紹介します。最後には、リアルタイムのGoogleデータを取得し、結果を解析するPythonスクリプトが完成します。
前提条件
- マシンにPythonがインストールされていること
- Scavio APIキー(free tierには月250クレジット含まれており、クレジットカードは不要です)
ステップ1: 依存関係のインストール
HTTPリクエストを行うためにrequestsをインストールします:
pip install requestsステップ2: 最初のGoogle検索を行う
クエリを指定してScavioのGoogle APIエンドポイントにPOSTリクエストを送信します。APIはorganic results, knowledge graph, People Also Askなどを含む構造化JSONを返します。
import requests
API_KEY = "your_scavio_api_key"
response = requests.post(
"https://api.scavio.dev/api/v1/search",
headers={
"x-api-key": API_KEY,
"Content-Type": "application/json",
},
json={"query": query},
)
data = response.json()
for result in data.get("organic_results", [])[:5]:
print(f"{result['position']}. {result['title']}")
print(f" {result['link']}\n")ステップ3: レスポンスの例
APIは構造化JSONを返します。以下はGoogle検索のレスポンス例です:
{
"search_metadata": {
"status": "success",
"total_results": 1240000000
},
"organic_results": [
{
"position": 1,
"title": "Best Noise-Cancelling Headphones of 2026",
"link": "https://example.com/best-headphones",
"snippet": "We tested 30+ headphones to find the best...",
"displayed_link": "example.com"
}
],
"knowledge_graph": {
"title": "Noise-cancelling headphones",
"description": "Active noise-cancelling headphones use..."
},
"people_also_ask": [
{ "question": "What are the best noise cancelling headphones right now?" },
{ "question": "Is noise cancelling bad for your ears?" }
]
}すべてのフィールドは構造化され型付けされています。HTML解析やCSSセレクタ、正規表現抽出は不要です。Pythonコードから任意のフィールドに直接アクセスできます。
ステップ4: 完全な動作例
以下は、Googleを検索して結果を表示する、完全で実行可能なPythonスクリプトです:
"""
Scrape Google search results using Scavio API.
Returns structured JSON with organic results, knowledge graph, People Also Ask, and more.
"""
import requests
import json
API_KEY = "your_scavio_api_key"
def search_google(query: str) -> dict:
response = requests.post(
"https://api.scavio.dev/api/v1/search",
headers={
"x-api-key": API_KEY,
"Content-Type": "application/json",
},
json={"query": query},
)
response.raise_for_status()
return response.json()
if __name__ == "__main__":
results = search_google("best noise cancelling headphones 2026")
print(json.dumps(results, indent=2))Scavioを直接Googleをスクレイピングする代わりに使う理由
- プロキシ管理が不要。 直接スクレイピングするにはIP禁止を避けるためにプロキシのローテーションが必要です。Scavioはこれらすべてをサーバー側で処理します。
- CAPTCHA解決不要。 Googleは自動リクエストを積極的にブロックします。Scavioは毎回クリーンなデータを返します。
- 構造化JSON出力。 HTML解析やCSSセレクタのメンテナンスは不要。毎回型付けされた一貫性のあるデータを取得できます。
- 単一APIで複数プラットフォーム。 同じAPIキーと同じ認証パターンでGoogle、Amazon、YouTube、Walmartを検索できます。
- 無料枠あり。 月250クレジット、クレジットカード不要。各検索は1クレジットです。