ScavioScavio
产品定价文档
登录开始使用
  1. 首页
  2. 教程
  3. 如何使用 SERP API 替换 YouTube 抓取
教程

如何使用 SERP API 替换 YouTube 抓取

停止直接抓取 YouTube。使用 SERP API 获取视频标题、频道和观看次数,而无需浏览器自动化或 API 配额问题。

获取免费API密钥API文档

YouTube 抓取很脆弱——页面布局发生变化、速率限制生效、浏览器自动化速度缓慢。当您使用 site:youtube.com 进行搜索时,SERP API 将 YouTube 视频数据作为结构化结果返回。您无需 Selenium、Playwright 或 YouTube Data API 配额即可获取视频标题、频道名称、观看次数和上传日期。每次搜索费用为 0.005 美元,最多返回 10 个视频结果。

前置条件

  • Python 3.9+ 或 Node.js 18+
  • 请求已安装库
  • 来自 scavio.dev 的 Scavio API 密钥

操作指南

步骤 1: 通过 SERP API 搜索 YouTube

在搜索查询中使用 site:youtube.com 即可获取仅限 YouTube 的结果。 SERP API 返回结构化数据,包括视频标题和频道信息。

Python
import requests, os

SCAVIO_KEY = os.environ['SCAVIO_API_KEY']

def search_youtube(query: str, count: int = 10) -> list:
    resp = requests.post('https://api.scavio.dev/api/v1/search',
        headers={'x-api-key': SCAVIO_KEY, 'Content-Type': 'application/json'},
        json={'query': f'site:youtube.com {query}',
              'country_code': 'us', 'num_results': count})
    resp.raise_for_status()
    results = resp.json().get('organic_results', [])
    videos = []
    for r in results:
        link = r.get('link', '')
        if 'youtube.com/watch' in link or 'youtu.be/' in link:
            videos.append({
                'title': r['title'].replace(' - YouTube', '').strip(),
                'url': link,
                'snippet': r.get('snippet', ''),
                'channel': extract_channel(r.get('snippet', '')),
            })
    return videos

def extract_channel(snippet: str) -> str:
    # YouTube snippets often start with channel name or duration
    parts = snippet.split('\n') if '\n' in snippet else snippet.split(' ... ')
    return parts[0].strip() if parts else ''

videos = search_youtube('python tutorial 2026')
for v in videos[:5]:
    print(f'{v["title"][:50]}: {v["channel"][:30]}')
print(f'Cost: $0.005 for {len(videos)} videos')

步骤 2: 建立视频研究管道

搜索多个主题并聚合视频数据以进行竞争分析、内容研究或影响者发现。

Python
import time

def research_videos(topics: list) -> dict:
    all_videos = {}
    for topic in topics:
        videos = search_youtube(topic, count=10)
        all_videos[topic] = videos
        time.sleep(0.3)
    # Aggregate stats
    total_videos = sum(len(v) for v in all_videos.values())
    channels = set()
    for videos in all_videos.values():
        for v in videos:
            if v['channel']:
                channels.add(v['channel'])
    print(f'Topics: {len(topics)}')
    print(f'Total videos found: {total_videos}')
    print(f'Unique channels: {len(channels)}')
    print(f'Cost: {len(topics)} queries = ${len(topics) * 0.005:.3f}')
    return all_videos

topics = ['python api tutorial', 'javascript tutorial 2026', 'react hooks explained']
data = research_videos(topics)
for topic, videos in data.items():
    print(f'\n{topic}: {len(videos)} videos')
    for v in videos[:2]:
        print(f'  {v["title"][:50]}')

步骤 3: 与 YouTube Data API 方法比较

显示 SERP API 和 YouTube 数据 API 在设置、配额和成本方面的差异。

Python
comparison = {
    'SERP API (Scavio)': {
        'setup': 'One API key, one POST call',
        'quota': 'No daily quota, pay per query',
        'cost': '$0.005/query (250 free/month)',
        'data': 'Title, URL, snippet, channel name',
        'rate_limit': '10 req/sec',
        'auth': 'API key in header',
    },
    'YouTube Data API v3': {
        'setup': 'Google Cloud project, OAuth consent, API enable',
        'quota': '10,000 units/day (search = 100 units = 100 searches/day)',
        'cost': 'Free up to quota, then blocked',
        'data': 'Full metadata, stats, thumbnails',
        'rate_limit': 'Quota-based',
        'auth': 'OAuth2 or API key + project',
    },
    'Scraping (Selenium)': {
        'setup': 'Browser driver, anti-detection, proxy',
        'quota': 'IP-based blocks, unpredictable',
        'cost': '$50-200/month for proxy + compute',
        'data': 'Anything visible on page',
        'rate_limit': '1-2 req/sec safely',
        'auth': 'None (but proxies needed)',
    },
}

for method, details in comparison.items():
    print(f'{method}:')
    for key, val in details.items():
        print(f'  {key}: {val}')
    print()

Python 示例

Python
import requests, os

SCAVIO_KEY = os.environ['SCAVIO_API_KEY']

def youtube_search(query, count=10):
    resp = requests.post('https://api.scavio.dev/api/v1/search',
        headers={'x-api-key': SCAVIO_KEY, 'Content-Type': 'application/json'},
        json={'query': f'site:youtube.com {query}', 'country_code': 'us', 'num_results': count})
    return [{'title': r['title'].replace(' - YouTube', ''), 'url': r['link']}
            for r in resp.json().get('organic_results', [])
            if 'youtube.com/watch' in r.get('link', '')]

videos = youtube_search('python tutorial 2026')
for v in videos[:5]:
    print(f'{v["title"][:50]}: {v["url"]}')

JavaScript 示例

JavaScript
const SCAVIO_KEY = process.env.SCAVIO_API_KEY;

async function youtubeSearch(query, count = 10) {
  const resp = await fetch('https://api.scavio.dev/api/v1/search', {
    method: 'POST',
    headers: { 'x-api-key': SCAVIO_KEY, 'Content-Type': 'application/json' },
    body: JSON.stringify({ query: `site:youtube.com ${query}`, country_code: 'us', num_results: count })
  });
  const data = await resp.json();
  return (data.organic_results || []).filter(r => r.link?.includes('youtube.com/watch'))
    .map(r => ({ title: r.title.replace(' - YouTube', ''), url: r.link }));
}

youtubeSearch('python tutorial 2026').then(v => v.forEach(x => console.log(x.title)));

预期输出

JSON
Python Tutorial for Beginners 2026 - Full Course: Corey Schafer
Learn Python in 1 Hour - 2026 Edition: Programming with Mosh
Python API Tutorial - Build Your First API: Tech With Tim

Cost: $0.005 for 8 videos

SERP API (Scavio):
  setup: One API key, one POST call
  quota: No daily quota, pay per query
  cost: $0.005/query (250 free/month)

相关教程

  • 如何构建 YouTube 影响者发现渠道
  • 如何构建 TikTok Creator 评分 API 管道
  • 如何通过 SERP 丰富构建本地潜在客户渠道

常见问题

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

Python 3.9+ 或 Node.js 18+. 请求已安装库. 来自 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
Solution

API YouTube

Read more
Solution

追踪YouTube频道、视频和趋势

Read more
Workflow

YouTube 网红 SERP 研究工作流

Read more
Glossary

SERP API

Read more

开始构建

停止直接抓取 YouTube。使用 SERP API 获取视频标题、频道和观看次数,而无需浏览器自动化或 API 配额问题。

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

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

产品

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

开发者

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

替代方案

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

工具

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

© 2026 Scavio. 保留所有权利。

Featured on TAAFT
服务条款隐私政策