serpapi

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

SerpApi

SerpApi

Use SerpApi via direct
curl
calls to scrape search engine results from Google, Bing, YouTube, and more.
Official docs:
https://serpapi.com/search-api

通过直接调用
curl
来使用SerpApi,从Google、Bing、YouTube等平台爬取搜索引擎结果
官方文档:
https://serpapi.com/search-api

When to Use

适用场景

Use this skill when you need to:
  • Scrape Google search results (organic, ads, knowledge graph)
  • Search Google Images, News, Videos, Shopping
  • Get local business results from Google Maps
  • Scrape other search engines (Bing, YouTube, DuckDuckGo, etc.)
  • Monitor SERP rankings for SEO analysis

当你需要以下操作时,可使用该技能:
  • 爬取Google搜索结果(自然搜索结果、广告、知识图谱)
  • 搜索Google图片、新闻、视频、购物信息
  • 从Google Maps获取本地商家结果
  • 爬取其他搜索引擎结果(Bing、YouTube、DuckDuckGo等)
  • 监控SERP排名以进行SEO分析

Prerequisites

前提条件

  1. Sign up at SerpApi
  2. Go to Dashboard and copy your API key
  3. Store it in the environment variable
    SERPAPI_API_KEY
bash
export SERPAPI_API_KEY="your-api-key"
  1. SerpApi注册账号
  2. 进入控制台并复制你的API密钥
  3. 将密钥存储到环境变量
    SERPAPI_API_KEY
bash
export SERPAPI_API_KEY="your-api-key"

Pricing

定价

  • Free tier: 100 searches/month
  • API key is passed as a query parameter
    api_key

Important: When using
$VAR
in a command that pipes to another command, wrap the command containing
$VAR
in
bash -c '...'
. Due to a Claude Code bug, environment variables are silently cleared when pipes are used directly.
bash
bash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"'
  • 免费层级:每月100次搜索
  • API密钥通过查询参数
    api_key
    传递

重要提示: 当在包含管道的命令中使用
$VAR
时,请将包含
$VAR
的命令用
bash -c '...'
包裹。由于Claude Code的一个bug,直接使用管道时环境变量会被静默清空。
bash
bash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"'

How to Use

使用方法

All examples below assume you have
SERPAPI_API_KEY
set.
Base URL:
https://serpapi.com/search

以下所有示例均假设你已设置好
SERPAPI_API_KEY
环境变量。
基础URL:
https://serpapi.com/search

1. Basic Google Search

1. 基础Google搜索

Search Google and get structured JSON results:
bash
bash -c 'curl -s "https://serpapi.com/search?engine=google&q=artificial+intelligence&api_key=${SERPAPI_API_KEY}"' | jq '.organic_results[:3] | .[] | {title, link, snippet}

搜索Google并获取结构化JSON结果:
bash
bash -c 'curl -s "https://serpapi.com/search?engine=google&q=artificial+intelligence&api_key=${SERPAPI_API_KEY}"' | jq '.organic_results[:3] | .[] | {title, link, snippet}

2. Search with Location

2. 指定地理位置搜索

Search from a specific location:
bash
bash -c 'curl -s "https://serpapi.com/search?engine=google&q=best+coffee+shops&location=San+Francisco,+California&gl=us&hl=en&api_key=${SERPAPI_API_KEY}"' | jq '.organic_results[:3]'
Parameters:
  • location
    : City, state, or address
  • gl
    : Country code (us, uk, de, etc.)
  • hl
    : Language code (en, de, fr, etc.)

从特定地理位置进行搜索:
bash
bash -c 'curl -s "https://serpapi.com/search?engine=google&q=best+coffee+shops&location=San+Francisco,+California&gl=us&hl=en&api_key=${SERPAPI_API_KEY}"' | jq '.organic_results[:3]'
参数说明:
  • location
    :城市、州或地址
  • gl
    :国家代码(如us、uk、de等)
  • hl
    :语言代码(如en、de、fr等)

3. Google Image Search

3. Google图片搜索

Search for images:
bash
bash -c 'curl -s "https://serpapi.com/search?engine=google_images&q=sunset+beach&api_key=${SERPAPI_API_KEY}"' | jq '.images_results[:3] | .[] | {title, original, thumbnail}

搜索图片:
bash
bash -c 'curl -s "https://serpapi.com/search?engine=google_images&q=sunset+beach&api_key=${SERPAPI_API_KEY}"' | jq '.images_results[:3] | .[] | {title, original, thumbnail}

4. Google News Search

4. Google新闻搜索

Search news articles:
bash
bash -c 'curl -s "https://serpapi.com/search?engine=google_news&q=technology&api_key=${SERPAPI_API_KEY}"' | jq '.news_results[:3] | .[] | {title, link, source, date}

搜索新闻文章:
bash
bash -c 'curl -s "https://serpapi.com/search?engine=google_news&q=technology&api_key=${SERPAPI_API_KEY}"' | jq '.news_results[:3] | .[] | {title, link, source, date}

5. Google Shopping Search

5. Google购物搜索

Search products:
bash
bash -c 'curl -s "https://serpapi.com/search?engine=google_shopping&q=wireless+headphones&api_key=${SERPAPI_API_KEY}"' | jq '.shopping_results[:3] | .[] | {title, price, source}

搜索产品:
bash
bash -c 'curl -s "https://serpapi.com/search?engine=google_shopping&q=wireless+headphones&api_key=${SERPAPI_API_KEY}"' | jq '.shopping_results[:3] | .[] | {title, price, source}

6. YouTube Search

6. YouTube搜索

Search YouTube videos:
bash
bash -c 'curl -s "https://serpapi.com/search?engine=youtube&search_query=python+tutorial&api_key=${SERPAPI_API_KEY}"' | jq '.video_results[:3] | .[] | {title, link, channel, views}

搜索YouTube视频:
bash
bash -c 'curl -s "https://serpapi.com/search?engine=youtube&search_query=python+tutorial&api_key=${SERPAPI_API_KEY}"' | jq '.video_results[:3] | .[] | {title, link, channel, views}

7. Google Maps / Local Results

7. Google Maps / 本地结果搜索

Search local businesses:
bash
bash -c 'curl -s "https://serpapi.com/search?engine=google_maps&q=restaurants&ll=@40.7128,-74.0060,15z&api_key=${SERPAPI_API_KEY}"' | jq '.local_results[:3] | .[] | {title, rating, address}
Parameters:
  • ll
    : Latitude, longitude, and zoom level (e.g.,
    @40.7128,-74.0060,15z
    )

搜索本地商家:
bash
bash -c 'curl -s "https://serpapi.com/search?engine=google_maps&q=restaurants&ll=@40.7128,-74.0060,15z&api_key=${SERPAPI_API_KEY}"' | jq '.local_results[:3] | .[] | {title, rating, address}
参数说明:
  • ll
    :纬度、经度和缩放级别(例如:
    @40.7128,-74.0060,15z

8. Pagination

8. 分页查询

Get more results using the
start
parameter:
bash
undefined
使用
start
参数获取更多结果:
bash
undefined

First page (results 1-10)

第一页(结果1-10)

Second page (results 11-20)

第二页(结果11-20)

9. Check Account Info

9. 查看账户信息

Check your API usage and credits:
bash
bash -c 'curl -s "https://serpapi.com/account?api_key=${SERPAPI_API_KEY}"' | jq '{plan_name, searches_per_month, this_month_usage}

查看你的API使用情况和剩余额度:
bash
bash -c 'curl -s "https://serpapi.com/account?api_key=${SERPAPI_API_KEY}"' | jq '{plan_name, searches_per_month, this_month_usage}

Supported Engines

支持的搜索引擎

EngineParameterDescription
Google Search
engine=google
Web search results
Google Images
engine=google_images
Image search
Google News
engine=google_news
News articles
Google Shopping
engine=google_shopping
Product search
Google Maps
engine=google_maps
Local businesses
YouTube
engine=youtube
Video search
Bing
engine=bing
Bing web search
DuckDuckGo
engine=duckduckgo
Privacy-focused search

搜索引擎参数描述
Google搜索
engine=google
网页搜索结果
Google图片
engine=google_images
图片搜索
Google新闻
engine=google_news
新闻文章
Google购物
engine=google_shopping
产品搜索
Google Maps
engine=google_maps
本地商家信息
YouTube
engine=youtube
视频搜索
Bing
engine=bing
Bing网页搜索
DuckDuckGo
engine=duckduckgo
隐私优先的搜索引擎

Common Parameters

通用参数

ParameterDescription
q
Search query (required)
engine
Search engine to use
location
Geographic location for search
gl
Country code (e.g., us, uk)
hl
Language code (e.g., en, de)
start
Pagination offset (0, 10, 20...)
num
Number of results (max 100)
safe
Safe search (
active
or
off
)
device
Device type (
desktop
,
mobile
,
tablet
)

参数描述
q
搜索关键词(必填)
engine
要使用的搜索引擎
location
搜索的地理位置
gl
国家代码(如us、uk等)
hl
语言代码(如en、de等)
start
分页偏移量(0、10、20...)
num
结果数量上限(最多100条)
safe
安全搜索设置(
active
off
device
设备类型(
desktop
mobile
tablet

Guidelines

注意事项

  1. Use specific engines: Use
    google_images
    ,
    google_news
    etc. instead of
    tbm
    parameter for cleaner results
  2. Add location for local searches: Use
    location
    and
    gl
    for geo-targeted results
  3. Cache results: SerpApi caches results by default; use
    no_cache=true
    for fresh data
  4. Monitor usage: Check
    /account
    endpoint to track API credits
  5. Use jq filters: Filter large JSON responses to extract only needed data
  1. 使用特定引擎参数:使用
    google_images
    google_news
    等参数,而非
    tbm
    参数,以获得更清晰的结果
  2. 本地搜索添加地理位置:使用
    location
    gl
    参数获取地理位置定向的结果
  3. 缓存结果:SerpApi默认会缓存结果;如需获取最新数据,使用
    no_cache=true
    参数
  4. 监控使用情况:通过
    /account
    端点跟踪API额度使用情况
  5. 使用jq过滤结果:通过jq过滤器从大型JSON响应中仅提取所需数据