この内容は古いバージョンです。最新バージョンを表示するには、戻るボタンを押してください。
バージョン:6
ページ更新者:T
更新日時:2026-06-11 07:07:02

タイトル: Google Trends
SEOタイトル: Google Trends API 完全ガイド (pytrends/非公式 API/SerpAPI)

この記事の要点
  • Google Trends には公式 API が存在しない。pytrends (Python 非公式) / SerpAPI / Glimpse / TrendsAPI Pro などサードパーティ経由で取得
  • 取得できる値は 絶対検索回数ではなく相対値 0〜100(期間内のピークを 100 とした正規化)
  • 対応する切り口: キーワード比較 / 地域別 (Interest by region) / 期間別 / 関連クエリ / 急上昇キーワード (Trending Searches)
  • 非公式エンドポイント https://trends.google.com/trends/api/explore を直接叩く方法もあるが、クッキー (NID) とトークン取得が必要で、レート制限・突然の仕様変更リスクあり
  • 商用利用や SLA が必要なら SerpAPI / Glimpse、研究/PoC なら pytrends、安価で大量なら TrendsAPI Pro を選択

Google Trends とは

Google Trends は Google 検索の人気度を可視化する無料サービスです。「特定キーワードが、ある期間にどれだけ検索されたか」を相対値で見られます。SEO 調査 / 季節性把握 / 競合分析 / ニュース解析で広く使われます。

ただし公式 API は提供されていません。データを自動取得するには、非公式ライブラリやサードパーティ API を使う必要があります。

主な取得手段の比較

手段言語料金SLA用途
pytrendsPython無料 (OSS)無し研究 / PoC / 個人
SerpAPI多言語 SDK$50/月〜あり (99.9%)商用 / 安定稼働
GlimpseWeb UI / API有料あり絶対検索回数推定が必要な場合
TrendsAPI ProREST$15/月〜あり安価で大量取得
直接スクレイピング自前無料無し非推奨 (BAN リスク)

pytrends (Python 非公式ライブラリ)

最も普及している Python ライブラリ。内部的に Google Trends の非公式 JSON エンドポイントを叩いて整形してくれます。

pip install pytrends
from pytrends.request import TrendReq

# hl=表示言語, tz=タイムゾーン (分単位、東京は -540)
pytrends = TrendReq(hl='ja-JP', tz=-540)

# キーワード設定 (最大5語まで同時比較可)
kw_list = ['Python', 'Ruby', 'PHP', 'Go']
pytrends.build_payload(
    kw_list,
    cat=0,                  # カテゴリ (0=All, 5=Computers)
    timeframe='today 12-m', # 過去12ヶ月
    geo='JP',               # 国コード (JP=日本)
    gprop=''                # 検索プロパティ (''=Web, 'news', 'images', 'youtube')
)

# 1. 時系列トレンド
trend_df = pytrends.interest_over_time()
print(trend_df.head())
#             Python  Ruby  PHP  Go  isPartial
# 2024-06-09      82    18   45  61      False

# 2. 地域別関心度
region_df = pytrends.interest_by_region(resolution='COUNTRY')
print(region_df.sort_values('Python', ascending=False).head())

# 3. 関連クエリ
related = pytrends.related_queries()
print(related['Python']['top'])      # トップ関連
print(related['Python']['rising'])   # 急上昇関連

# 4. 関連トピック
related_topics = pytrends.related_topics()

# 5. 急上昇キーワード(日次)
trending = pytrends.trending_searches(pn='japan')
print(trending.head(10))

注意: 相対値 (0〜100) であること

pytrends も Web UI も絶対検索回数を返しません。値は次のように正規化されます:

- 期間内 / 指定キーワード群の中で「最も検索された地点」を 100 とする
- 他の地点・他のキーワードは、その 100 に対する相対値 (0〜100)
- 「100」は絶対値ではなく、「ピーク時点」を示すだけ

つまり:
  「Python」単独で 100 = ピーク時 100% 検索された
  「Python」と「Ruby」を比較して Python=80, Ruby=10
    → Python は Ruby の 8 倍検索された (期間ピーク基準)

絶対検索回数の推定が必要なら Glimpse / Keyword Planner を併用。

SerpAPI 経由 (商用おすすめ)

SerpAPI は Google Trends を含む各種 Google サービスを REST API で叩けます。SLA とサポート付きで商用利用しやすい。

curl "https://serpapi.com/search?engine=google_trends&q=Python,Ruby&date=today+12-m&geo=JP&api_key=YOUR_KEY"
from serpapi import GoogleSearch

params = {
    "engine": "google_trends",
    "q": "Python,Ruby,PHP",
    "data_type": "TIMESERIES",   # TIMESERIES / GEO_MAP / RELATED_TOPICS / RELATED_QUERIES
    "date": "today 12-m",
    "geo": "JP",
    "api_key": "YOUR_SERPAPI_KEY",
}
results = GoogleSearch(params).get_dict()
print(results["interest_over_time"]["timeline_data"][:3])

非公式エンドポイント直叩き (上級者向け)

pytrends も内部でこれを使っています。仕組み理解のみ:

1. https://trends.google.com/trends/api/explore?req=...&tz=...&hl=...
   → トークン (widgets) を取得
2. https://trends.google.com/trends/api/widgetdata/multiline?...&token=...
   → 時系列データ取得 (先頭5バイト ")]}'," を捨てて JSON パース)

ハマりどころ:
- NID クッキーが無いと 429 になりやすい
- レスポンス先頭の XSSI プレフィックス ")]}'," を除去必須
- 短時間多発で IP 単位の一時 BAN
- 仕様が予告なく変わる

レート制限と対策

症状原因対策
429 Too Many Requests短時間多発1〜5 秒のスリープ、指数バックオフ
ResponseError 数日継続IP 単位の BANプロキシローテーション or SerpAPI 移行
空のデータフレームマイナーすぎるキーワードキーワード変更 or 期間延長
キーワード5語超でエラー1リクエスト最大5語5語ずつバッチ化し基準語で正規化

SEO 調査での実践例

# 5語を超える比較は、共通の基準語を入れてバッチ化+正規化
import pandas as pd
from pytrends.request import TrendReq

pytrends = TrendReq(hl='ja-JP', tz=-540)
keywords = ['Python','Ruby','PHP','Go','Rust','Java','TypeScript','Kotlin','Swift']
anchor = 'Python'  # 全バッチに共通で入れる基準語

dfs = []
for i in range(0, len(keywords), 4):
    batch = [anchor] + [k for k in keywords[i:i+4] if k != anchor]
    pytrends.build_payload(batch, timeframe='today 12-m', geo='JP')
    df = pytrends.interest_over_time().drop(columns=['isPartial'])
    dfs.append(df)

# anchor の値で正規化
merged = dfs[0]
for df in dfs[1:]:
    scale = merged[anchor].mean() / df[anchor].mean()
    df = df * scale
    merged = merged.join(df.drop(columns=[anchor]), how='outer')
print(merged.tail())

FAQ

Q: Google Cloud に Trends の API は無いの?
A: 2026 年現在ありません。Google は公式 API を公開していません。BigQuery 公開データセットにも Trends は含まれません。

Q: pytrends が突然動かなくなった
A: Google が内部仕様を変えるとよくあります。GitHub の最新版 (master) を入れ直すか、SerpAPI に切り替えるのが安定です。

Q: 検索回数の「実数」を知りたい
A: Trends は相対値しか返しません。Glimpse(推定実数を返す商用サービス)か、Google 広告の キーワードプランナー を併用してください。

Q: 利用規約上問題ないか
A: Google の規約はスクレイピングを禁止しています。商用や本番では SerpAPI 等の正規 API を経由するのが安全です。