ScavioScavio
产品定价文档
登录开始使用
  1. 首页
  2. 教程
  3. 如何构建有竞争力的 SERP 监控器
教程

如何构建有竞争力的 SERP 监控器

每天监控竞争对手的关键词排名,检测排名变化,并对新进入者发出警报。 Python 管道的价格为 0.005 美元/检查。

获取免费API密钥API文档

排名跟踪工具每月收费 50-300 美元,最多每天更新一次。定制的竞争性 SERP 监控器按照您自己的频率准确检查您关心的关键字,并就对您的业务重要的变化发出警报。本教程构建了一个监控器,可以以 0.005 美元/检查的价格跨关键字集跟踪多个竞争对手,并在位置波动时通过 Slack 或电子邮件发出警报。

前置条件

  • Python 3.8+
  • 请求库
  • 来自 scavio.dev 的 Scavio API 密钥
  • 竞争对手域名和目标关键词

操作指南

步骤 1: 定义竞争对手和关键词

设置监控配置。

Python
import os, requests, json, sqlite3
from datetime import datetime

API_KEY = os.environ['SCAVIO_API_KEY']
SH = {'x-api-key': API_KEY, 'Content-Type': 'application/json'}

CONFIG = {
    'competitors': ['serpapi.com', 'dataforseo.com', 'serper.dev', 'exa.ai', 'tavily.com'],
    'keywords': [
        'serp api', 'search api for developers', 'google search api python',
        'web scraping api 2026', 'ai agent search api'
    ]
}

db = sqlite3.connect('serp_monitor.db')
db.execute('''CREATE TABLE IF NOT EXISTS rankings (
    keyword TEXT, domain TEXT, position INTEGER,
    checked_at TEXT, title TEXT
)''')
db.commit()
print(f'Monitoring {len(CONFIG["competitors"])} competitors across {len(CONFIG["keywords"])} keywords')
print(f'Daily cost: ${len(CONFIG["keywords"]) * 0.005:.3f}')

步骤 2: 查看所有关键词的排名

对每个关键字运行 SERP 检查并记录竞争对手的排名。

Python
def check_rankings(keywords, competitors):
    results = []
    for kw in keywords:
        data = requests.post('https://api.scavio.dev/api/v1/search',
            headers=SH, json={'query': kw, 'country_code': 'us'}).json()
        organic = data.get('organic_results', [])
        now = datetime.now().isoformat()
        for r in organic[:20]:
            domain = r.get('link', '').split('/')[2] if r.get('link') else ''
            domain = domain.replace('www.', '')
            if domain in competitors:
                pos = r.get('position', 99)
                db.execute('INSERT INTO rankings VALUES (?,?,?,?,?)',
                    (kw, domain, pos, now, r.get('title', '')[:80]))
                results.append({'keyword': kw, 'domain': domain, 'position': pos})
        db.commit()
    print(f'Checked {len(keywords)} keywords. Cost: ${len(keywords) * 0.005:.3f}')
    return results

ranks = check_rankings(CONFIG['keywords'], CONFIG['competitors'])
for r in ranks[:10]:
    print(f'  {r["keyword"]:30} | {r["domain"]:20} | #{r["position"]}')

步骤 3: 检测位置变化

将当前检查与之前的检查进行比较以查找移动者。

Python
def detect_changes(keyword, domain, threshold=3):
    rows = db.execute(
        'SELECT position, checked_at FROM rankings WHERE keyword=? AND domain=? ORDER BY checked_at DESC LIMIT 2',
        (keyword, domain)).fetchall()
    if len(rows) < 2: return None
    current, previous = rows[0][0], rows[1][0]
    change = previous - current  # positive = improved
    if abs(change) >= threshold:
        return {'keyword': keyword, 'domain': domain,
                'previous': previous, 'current': current, 'change': change}
    return None

def alert_changes(keywords, competitors, threshold=3):
    alerts = []
    for kw in keywords:
        for comp in competitors:
            change = detect_changes(kw, comp, threshold)
            if change: alerts.append(change)
    if alerts:
        print(f'\n{len(alerts)} position changes detected:')
        for a in alerts:
            direction = 'UP' if a['change'] > 0 else 'DOWN'
            print(f'  {a["domain"]:20} | {a["keyword"]:25} | #{a["previous"]} -> #{a["current"]} ({direction} {abs(a["change"])})')
    else:
        print('No significant position changes.')
    return alerts

alert_changes(CONFIG['keywords'], CONFIG['competitors'])

步骤 4: 生成有竞争力的仪表板数据

构建竞争格局的摘要视图。

Python
def dashboard(competitors, keywords):
    print(f'\n{"Keyword":30} | ', end='')
    for c in competitors[:5]: print(f'{c[:12]:12} | ', end='')
    print()
    print('-' * (32 + 15 * len(competitors[:5])))
    for kw in keywords:
        print(f'{kw[:30]:30} | ', end='')
        for comp in competitors[:5]:
            row = db.execute(
                'SELECT position FROM rankings WHERE keyword=? AND domain=? ORDER BY checked_at DESC LIMIT 1',
                (kw, comp)).fetchone()
            pos = f'#{row[0]}' if row else '-'
            print(f'{pos:12} | ', end='')
        print()
    total_checks = len(keywords)
    print(f'\nMonthly cost estimate: ${total_checks * 0.005 * 30:.2f} (daily) or ${total_checks * 0.005 * 7:.2f} (weekly)')

# Run a check first, then display
check_rankings(CONFIG['keywords'], CONFIG['competitors'])
dashboard(CONFIG['competitors'], CONFIG['keywords'])

Python 示例

Python
import os, requests
SH = {'x-api-key': os.environ['SCAVIO_API_KEY'], 'Content-Type': 'application/json'}

def check(keyword, competitors):
    data = requests.post('https://api.scavio.dev/api/v1/search',
        headers=SH, json={'query': keyword, 'country_code': 'us'}).json()
    for r in data.get('organic_results', [])[:20]:
        domain = r.get('link', '').split('/')[2].replace('www.', '')
        if domain in competitors:
            print(f'{keyword}: {domain} at #{r["position"]}')

check('serp api', ['serpapi.com', 'dataforseo.com', 'serper.dev'])

JavaScript 示例

JavaScript
const SH = { 'x-api-key': process.env.SCAVIO_API_KEY, 'Content-Type': 'application/json' };
async function check(keyword, competitors) {
  const data = await fetch('https://api.scavio.dev/api/v1/search', {
    method: 'POST', headers: SH,
    body: JSON.stringify({ query: keyword, country_code: 'us' })
  }).then(r => r.json());
  for (const r of (data.organic_results || []).slice(0, 20)) {
    const domain = new URL(r.link).hostname.replace('www.', '');
    if (competitors.includes(domain))
      console.log(`${keyword}: ${domain} at #${r.position}`);
  }
}
check('serp api', ['serpapi.com', 'dataforseo.com', 'serper.dev']).catch(console.error);

预期输出

JSON
Monitoring 5 competitors across 5 keywords
Daily cost: $0.025
Checked 5 keywords. Cost: $0.025

Keyword                        | serpapi.com  | dataforseo.c | serper.dev   | exa.ai       | tavily.com   |
-----------------------------------------------------------------------------------------------
serp api                       | #3           | #7           | #5           | #12          | #15          |
search api for developers      | #4           | #8           | #6           | #9           | -            |
google search api python       | #2           | #5           | #4           | -            | -            |
web scraping api 2026          | #6           | #3           | #8           | -            | -            |
ai agent search api            | #5           | -            | #7           | #4           | #11          |

Monthly cost estimate: $3.75 (daily) or $0.88 (weekly)

相关教程

  • 如何建立历史 SERP 档案
  • 如何使用搜索 API 构建自定义 SEO 仪表板
  • 如何监控排名之外的搜索表面

常见问题

大多数开发者在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

开始构建

每天监控竞争对手的关键词排名,检测排名变化,并对新进入者发出警报。 Python 管道的价格为 0.005 美元/检查。

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

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

产品

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

开发者

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

替代方案

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

工具

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

© 2026 Scavio. 保留所有权利。

Featured on TAAFT
服务条款隐私政策