Google 搜索 API
获取 Google 搜索的自然结果、广告、相关搜索、知识图谱等信息。设置 engine=google 并传入查询字符串,即可获取绕过验证码和反爬虫防护的结构化结果。
Endpoint
Section titled “Endpoint” GET https://serp.shifter.io/v1?engine=google&api_key=YOUR_API_KEY
Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
api_key | string | yes | 您的 SERP API 密钥 |
engine | string | yes | 必须为 google |
q | string | yes | 搜索查询词 |
cookie | string | no | 请求使用的自定义 cookie,必须进行 URL 编码 |
tbm | string | no | 搜索垂直类型:isch(图片)、vid(视频)、nws(新闻)、shop(购物) |
sort_by | string | no | 按 relevance 或 date 对结果排序 |
time_period | string | no | last_hour、last_day、last_week、last_month、last_year 或 custom |
time_period_min | string | no | 当 time_period=custom 时的最小日期,格式为 MM/DD/YYYY |
time_period_max | string | no | 当 time_period=custom 时的最大日期,格式为 MM/DD/YYYY |
flatten_results | int | no | 1 表示展平结果,0 表示不展平 |
empty_results | int | no | 0 表示隐藏空结果,1 表示显示空结果 |
device | string | no | desktop、mobile 或 tablet |
location | string | no | 地理定位位置名称 |
google_domain | string | no | 要使用的 Google 域名(例如 google.co.uk) |
uule | string | no | Google 编码的位置字符串 |
lr | string | no | 语言限制,格式为 lang_xx |
hl | string | no | 界面语言代码 |
gl | string | no | 国家代码 |
start | int | no | 分页的结果偏移量 |
num | int | no | 每页结果数量 |
ijn | int | no | Google 图片的页码(每页 100 张图片) |
safe | string | no | 安全搜索:active 或 off |
filter | int | no | 相似及省略结果过滤:1 开启,0 关闭 |
nfpr | int | no | 1 表示排除自动纠正后的查询,0 表示不排除 |
tbs | string | no | 高级搜索参数(专利、日期等) |
ludocid | string | no | Google 我的商家 CID(Place ID) |
lsig | int | no | 强制使用知识图谱地图视图 |
Example request
Section titled “Example request”curl "https://serp.shifter.io/v1?engine=google&api_key=YOUR_API_KEY&q=history"import requests
params = { "engine": "google", "api_key": "YOUR_API_KEY", "q": "history",}r = requests.get("https://serp.shifter.io/v1", params=params)data = r.json()import fetch from 'node-fetch';
const url = 'https://serp.shifter.io/v1?' + new URLSearchParams({ engine: 'google', api_key: 'YOUR_API_KEY', q: 'history',});const data = await (await fetch(url)).json();Example response
Section titled “Example response”{ "search_metadata": { "id": "...", "status": "Success", "created_at": "2024-01-01T00:00:00Z" }, "search_parameters": { "engine": "google", "q": "history", "google_domain": "google.com", "device": "desktop" }, "search_information": { "total_results": 10500000000, "time_taken_displayed": 0.52 }, "organic_results": [ { "position": 1, "title": "History - Wikipedia", "link": "https://en.wikipedia.org/wiki/History", "displayed_link": "https://en.wikipedia.org > wiki > History", "snippet": "History is the systematic study of the past..." } ], "related_searches": [ { "query": "world history" } ], "pagination": { "current": 1, "next": "..." }}