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 | 对应接口 | 每次积分 |
|---|---|---|
google | Google Web Search | 1 |
google_images | Google Images Search | 1 |
google_news | Google News Search | 1 |
google_videos | Google Videos Search | 1 |
google_autocomplete | Google Search Autocomplete | 1 |
google_shopping | Google Shopping Search | 2 |
google_jobs | Google Jobs Search | 2 |
google_patents_details | Google Patent Details | 2 |
google_play | Google Play Search | 1 |
google_play_product | Google Play App Details | 1 |
google_trends | Google Trends | 2 |
google_trends_autocomplete | Google Trends Autocomplete | 2 |
google_trends_trending_now | Google Trends Trending Now | 2 |
google_maps | Google Maps Search | 2 |
google_maps_reviews | Google Maps Reviews | 2 |
duckduckgo | DuckDuckGo Search | 1 |
youtube | YouTube Search | 1 |
youtube_video_transcript | YouTube Video Transcripts | 2 |
amazon | Amazon Product Search | 2 |
amazon_product | Amazon Product Details | 2 |
amazon_autocomplete | Amazon Search Autocomplete | 1 |
walmart | Walmart Product Search | 2 |
walmart_product | Walmart Product Details | 2 |
ebay | eBay Product Search | 1 |
ebay_product | eBay Product Details | 2 |
apple_product | Apple Product Details | 1 |
与 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"。失败的搜索不扣费。