ScavioScavio
产品定价文档
登录开始使用
  1. 首页
  2. 教程
  3. 如何通过搜索 API 跟踪 Google 趋势
教程

如何通过搜索 API 跟踪 Google 趋势

通过跟踪搜索结果随时间的变化来监控趋势主题。通过每日 API 查询检测上升的查询、季节性模式和主题动量。

获取免费API密钥API文档

通过每天查询相同的关键字、测量结果新鲜度和内容变化以及检测新主题何时开始在搜索结果中一致出现来跟踪 Google 搜索趋势。 Google 趋势提供聚合兴趣数据,但不会向您显示某个主题的实际内容排名。通过直接跟踪搜索结果,您可以看到哪些页面正在上升,哪些主题正在生成新内容,以及 SERP 组成如何随时间变化,从而为您提供可操作的内容智能。

前置条件

  • 已安装 Python 3.8+
  • 请求已安装库
  • 来自 scavio.dev 的 Scavio API 密钥
  • 一组要跟踪的关键字

操作指南

步骤 1: 定义跟踪的关键字

设置您想要监控趋势信号的关键字和类别。

Python
import os, requests, json, datetime, hashlib

API_KEY = os.environ['SCAVIO_API_KEY']

TRACKED = [
    {'keyword': 'ai agent framework', 'category': 'tech'},
    {'keyword': 'remote work tools', 'category': 'productivity'},
    {'keyword': 'search api', 'category': 'tech'},
    {'keyword': 'cold email tools', 'category': 'sales'},
]

TRENDS_FILE = 'trends_history.json'

print(f'Tracking {len(TRACKED)} keywords for trends')

步骤 2: 捕获每日 SERP 快照

搜索每个关键字并存储结果快照以进行比较。

Python
def capture_snapshot(keyword: str) -> dict:
    resp = requests.post('https://api.scavio.dev/api/v1/search',
        headers={'x-api-key': API_KEY},
        json={'platform': 'google', 'query': keyword}, timeout=15)
    data = resp.json()
    results = data.get('organic_results', [])
    return {
        'keyword': keyword,
        'date': datetime.date.today().isoformat(),
        'result_count': len(results),
        'top_5_titles': [r.get('title', '') for r in results[:5]],
        'top_5_urls': [r.get('link', '') for r in results[:5]],
        'content_hash': hashlib.md5(json.dumps([r.get('title', '') for r in results[:5]]).encode()).hexdigest(),
        'has_featured_snippet': 'featured_snippet' in data or 'answer_box' in data,
        'paa_count': len(data.get('people_also_ask', [])),
    }

snap = capture_snapshot('ai agent framework')
print(f"{snap['keyword']}: {snap['result_count']} results, hash={snap['content_hash'][:8]}")

步骤 3: 检测内容速度

衡量搜索结果的变化速度以识别趋势主题。

Python
def load_history() -> list:
    try:
        with open(TRENDS_FILE) as f:
            return json.load(f)
    except FileNotFoundError:
        return []

def save_history(history: list):
    with open(TRENDS_FILE, 'w') as f:
        json.dump(history, f, indent=2)

def content_velocity(keyword: str, history: list) -> dict:
    entries = [h for h in history if h['keyword'] == keyword]
    entries.sort(key=lambda x: x['date'])
    if len(entries) < 2:
        return {'velocity': 'unknown', 'changes': 0}
    recent = entries[-5:] if len(entries) >= 5 else entries
    changes = 0
    for i in range(1, len(recent)):
        if recent[i]['content_hash'] != recent[i-1]['content_hash']:
            changes += 1
    velocity = changes / (len(recent) - 1)
    return {
        'velocity': 'high' if velocity > 0.6 else 'medium' if velocity > 0.3 else 'low',
        'changes': changes,
        'days_tracked': len(recent),
    }

history = load_history()
vel = content_velocity('ai agent framework', history)
print(f"Velocity: {vel['velocity']} ({vel['changes']} changes)")

步骤 4: 运行每日跟踪

执行日常跟踪例程并存储结果。

Python
import time

def daily_track(tracked: list) -> list:
    history = load_history()
    snapshots = []
    for item in tracked:
        snap = capture_snapshot(item['keyword'])
        snap['category'] = item['category']
        snapshots.append(snap)
        history.append(snap)
        vel = content_velocity(item['keyword'], history)
        print(f"  {item['keyword']}: velocity={vel['velocity']}")
        time.sleep(0.3)
    save_history(history)
    return snapshots

snapshots = daily_track(TRACKED)

步骤 5: 生成趋势报告

根据内容速度和 SERP 变化生成一份报告,显示哪些主题呈上升趋势。

Python
def trends_report(tracked: list) -> str:
    history = load_history()
    lines = [f'Trends Report - {datetime.date.today().isoformat()}', '']
    trending = []
    for item in tracked:
        vel = content_velocity(item['keyword'], history)
        entries = [h for h in history if h['keyword'] == item['keyword']]
        latest = entries[-1] if entries else {}
        status = 'TRENDING' if vel['velocity'] == 'high' else 'STABLE' if vel['velocity'] == 'low' else 'WATCH'
        lines.append(f"[{status}] {item['keyword']} ({item['category']})")
        lines.append(f"  Velocity: {vel['velocity']}, Top: {latest.get('top_5_titles', [''])[0][:50]}")
        if vel['velocity'] == 'high':
            trending.append(item['keyword'])
    lines.append(f'\nTrending topics: {len(trending)}')
    report = '\n'.join(lines)
    print(report)
    return report

trends_report(TRACKED)

Python 示例

Python
import requests, os, hashlib, json
H = {'x-api-key': os.environ['SCAVIO_API_KEY']}

def serp_hash(keyword):
    data = requests.post('https://api.scavio.dev/api/v1/search', headers=H,
        json={'platform': 'google', 'query': keyword}).json()
    titles = [r.get('title', '') for r in data.get('organic_results', [])[:5]]
    return hashlib.md5(json.dumps(titles).encode()).hexdigest()[:8]

print(serp_hash('ai agent framework'))

JavaScript 示例

JavaScript
const H = {'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json'};
async function serpHash(keyword) {
  const r = await fetch('https://api.scavio.dev/api/v1/search', {
    method: 'POST', headers: H,
    body: JSON.stringify({platform: 'google', query: keyword})
  });
  const titles = ((await r.json()).organic_results || []).slice(0, 5).map(r => r.title);
  return titles.join('|').slice(0, 40);
}
serpHash('ai agent framework').then(console.log);

预期输出

JSON
A daily trend tracking system that monitors SERP changes, measures content velocity, and identifies trending topics based on how fast search results are shifting.

相关教程

  • 如何使用搜索 API 每日跟踪地理指标
  • 如何将 Surfer SEO 与搜索 API 结合起来

常见问题

大多数开发者在15到30分钟内完成本教程。您需要一个Scavio API密钥(免费套餐即可)和可用的Python或JavaScript环境。

已安装 Python 3.8+. 请求已安装库. 来自 scavio.dev 的 Scavio API 密钥. 一组要跟踪的关键字. Scavio API密钥注册即送50个免费积分。

可以。免费套餐注册即送50个积分,完全足够完成本教程并构建一个可运行的原型解决方案。

Scavio提供原生LangChain包(langchain-scavio)、MCP服务器以及适用于任何HTTP客户端的REST API。本教程使用 the raw REST API, 但您可以根据需要适配您选择的框架。

相关资源

Best Of

2026 年最佳基于队列的 SERP API

Read more
Best Of

2026年最佳SERP API

Read more
Glossary

SERP API

Read more
Glossary

SERP API 队列系统

Read more
Comparison

Semrush API vs Raw SERP API

Read more
Solution

从SERP API获取Google Ads数据

Read more

开始构建

通过跟踪搜索结果随时间的变化来监控趋势主题。通过每日 API 查询检测上升的查询、季节性模式和主题动量。

获取免费API密钥阅读文档
ScavioScavio

面向AI智能体的实时搜索API。搜索所有平台,不仅仅是Google。

产品

  • 功能
  • 定价
  • 控制台
  • 联盟计划

开发者

  • 文档
  • API参考
  • 快速开始
  • MCP集成
  • Python SDK

替代方案

  • Tavily替代方案
  • SerpAPI替代方案
  • Firecrawl替代方案
  • Exa替代方案

工具

  • JSON格式化
  • cURL转代码
  • Token计数器
  • 全部工具

© 2026 Scavio. 保留所有权利。

Featured on TAAFT
服务条款隐私政策