SerpBase

SerpApi 兼容接口

为 SerpApi 写的代码只要换一个接口地址就能用:同样的 engine 名称、参数和返回字段,按 SerpBase 的价格计费。

怎么切换

把 https://serpapi.com/search.json 换成下面的地址,api_key 填你的 SerpBase Key。和 SerpApi 一样用 GET 请求。Key 也可以放在 X-API-Key 请求头里,这样不会出现在网址和日志中。

BASH
curl "https://api.serpbase.dev/google/serpapi/search.json?engine=google&q=coffee&gl=us&hl=en" \
  -H "X-API-Key: YOUR_API_KEY"

curl "https://api.serpbase.dev/google/serpapi/search.json?engine=amazon&k=headphones&amazon_domain=amazon.com" \
  -H "X-API-Key: YOUR_API_KEY"
PYTHON
import requests

res = requests.get(
    "https://api.serpbase.dev/google/serpapi/search.json",
    headers={"X-API-Key": "YOUR_API_KEY"},
    params={"engine": "google_news", "q": "semiconductors", "gl": "us"},
)
print(res.json()["news_results"][0]["title"])

支持的 engine

每个 engine 由第二列的 SerpBase 接口执行,价格与该接口相同。不在列表中的 engine 会返回 400。

engine对应接口每次积分
googleGoogle Web Search1
google_imagesGoogle Images Search1
google_newsGoogle News Search1
google_videosGoogle Videos Search1
google_autocompleteGoogle Search Autocomplete1
google_shoppingGoogle Shopping Search2
google_jobsGoogle Jobs Search2
google_patents_detailsGoogle Patent Details2
google_playGoogle Play Search1
google_play_productGoogle Play App Details1
google_trendsGoogle Trends2
google_trends_autocompleteGoogle Trends Autocomplete2
google_trends_trending_nowGoogle Trends Trending Now2
google_mapsGoogle Maps Search2
google_maps_reviewsGoogle Maps Reviews2
duckduckgoDuckDuckGo Search1
youtubeYouTube Search1
youtube_video_transcriptYouTube Video Transcripts2
amazonAmazon Product Search2
amazon_productAmazon Product Details2
amazon_autocompleteAmazon Search Autocomplete1
walmartWalmart Product Search2
walmart_productWalmart Product Details2
ebayeBay Product Search1
ebay_producteBay Product Details2
apple_productApple Product Details1

与 SerpApi 的不同

  • 返回的是 SerpBase 能提取的字段,按 SerpApi 的字段名输出。SerpBase 没有的字段会直接省略而不会猜测填充,读取前请先判断字段是否存在。
  • 暂不支持:output=html(engine=google 除外)、google_maps 的地点详情查询(请用 /google/maps/detail)、google_trends 中 TIMESERIES 以外的 data_type、apps 以外的 Play 商店,以及 SerpApi 的账户、存档和异步接口。no_cache、async、json_restrictor 可以传,但不起作用。
  • 错误格式与 SerpApi 一致:被拒绝的请求返回 400、401 或 429,内容为 {"error": …};执行了但失败的搜索返回 200,search_metadata.status 为 "Error"。失败的搜索不扣费。