serpapi
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSerpApi
SerpApi
Use SerpApi via direct calls to scrape search engine results from Google, Bing, YouTube, and more.
curlOfficial docs:https://serpapi.com/search-api
通过直接调用来使用SerpApi,从Google、Bing、YouTube等平台爬取搜索引擎结果。
curl官方文档: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
前提条件
- Sign up at SerpApi
- Go to Dashboard and copy your API key
- Store it in the environment variable
SERPAPI_API_KEY
bash
export SERPAPI_API_KEY="your-api-key"- 在SerpApi注册账号
- 进入控制台并复制你的API密钥
- 将密钥存储到环境变量中
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 usingin a command that pipes to another command, wrap the command containing$VARin$VAR. Due to a Claude Code bug, environment variables are silently cleared when pipes are used directly.bash -c '...'bashbash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"'
- 免费层级:每月100次搜索
- API密钥通过查询参数传递
api_key
重要提示: 当在包含管道的命令中使用时,请将包含$VAR的命令用$VAR包裹。由于Claude Code的一个bug,直接使用管道时环境变量会被静默清空。bash -c '...'bashbash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"'
How to Use
使用方法
All examples below assume you have set.
SERPAPI_API_KEYBase URL:
https://serpapi.com/search以下所有示例均假设你已设置好环境变量。
SERPAPI_API_KEY基础URL:
https://serpapi.com/search1. 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:
- : City, state, or address
location - : Country code (us, uk, de, etc.)
gl - : Language code (en, de, fr, etc.)
hl
从特定地理位置进行搜索:
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 - :国家代码(如us、uk、de等)
gl - :语言代码(如en、de、fr等)
hl
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:
- : Latitude, longitude, and zoom level (e.g.,
ll)@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 parameter:
startbash
undefined使用参数获取更多结果:
startbash
undefinedFirst page (results 1-10)
第一页(结果1-10)
bash -c 'curl -s "https://serpapi.com/search?engine=google&q=machine+learning&start=0&api_key=${SERPAPI_API_KEY}"' | jq '.organic_results | length'
bash -c 'curl -s "https://serpapi.com/search?engine=google&q=machine+learning&start=0&api_key=${SERPAPI_API_KEY}"' | jq '.organic_results | length'
Second page (results 11-20)
第二页(结果11-20)
bash -c 'curl -s "https://serpapi.com/search?engine=google&q=machine+learning&start=10&api_key=${SERPAPI_API_KEY}"' | jq '.organic_results | length'
---bash -c 'curl -s "https://serpapi.com/search?engine=google&q=machine+learning&start=10&api_key=${SERPAPI_API_KEY}"' | jq '.organic_results | length'
---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
支持的搜索引擎
| Engine | Parameter | Description |
|---|---|---|
| Google Search | | Web search results |
| Google Images | | Image search |
| Google News | | News articles |
| Google Shopping | | Product search |
| Google Maps | | Local businesses |
| YouTube | | Video search |
| Bing | | Bing web search |
| DuckDuckGo | | Privacy-focused search |
| 搜索引擎 | 参数 | 描述 |
|---|---|---|
| Google搜索 | | 网页搜索结果 |
| Google图片 | | 图片搜索 |
| Google新闻 | | 新闻文章 |
| Google购物 | | 产品搜索 |
| Google Maps | | 本地商家信息 |
| YouTube | | 视频搜索 |
| Bing | | Bing网页搜索 |
| DuckDuckGo | | 隐私优先的搜索引擎 |
Common Parameters
通用参数
| Parameter | Description |
|---|---|
| Search query (required) |
| Search engine to use |
| Geographic location for search |
| Country code (e.g., us, uk) |
| Language code (e.g., en, de) |
| Pagination offset (0, 10, 20...) |
| Number of results (max 100) |
| Safe search ( |
| Device type ( |
| 参数 | 描述 |
|---|---|
| 搜索关键词(必填) |
| 要使用的搜索引擎 |
| 搜索的地理位置 |
| 国家代码(如us、uk等) |
| 语言代码(如en、de等) |
| 分页偏移量(0、10、20...) |
| 结果数量上限(最多100条) |
| 安全搜索设置( |
| 设备类型( |
Guidelines
注意事项
- Use specific engines: Use ,
google_imagesetc. instead ofgoogle_newsparameter for cleaner resultstbm - Add location for local searches: Use and
locationfor geo-targeted resultsgl - Cache results: SerpApi caches results by default; use for fresh data
no_cache=true - Monitor usage: Check endpoint to track API credits
/account - Use jq filters: Filter large JSON responses to extract only needed data
- 使用特定引擎参数:使用、
google_images等参数,而非google_news参数,以获得更清晰的结果tbm - 本地搜索添加地理位置:使用和
location参数获取地理位置定向的结果gl - 缓存结果:SerpApi默认会缓存结果;如需获取最新数据,使用参数
no_cache=true - 监控使用情况:通过端点跟踪API额度使用情况
/account - 使用jq过滤结果:通过jq过滤器从大型JSON响应中仅提取所需数据