通过每天查询相同的关键字、测量结果新鲜度和内容变化以及检测新主题何时开始在搜索结果中一致出现来跟踪 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.