公共信息
基础参数
| 参数 | 描述 |
|---|---|
| BasePath | 调用 API 的基础路径 |
| Endpoint | 调用 API 时生成的随机路径 |
| AccessKey | 调用 API 的 AccessKey |
请求路径
https://{BasePath}/search/{Endpoint}/smart
请求方法
GET
请求头
| 参数 | 类型 | 描述 |
|---|---|---|
| Authorization | String | 输入:Bearer {AK},其中 AK 为 AccessKey |
| Pragma | String | 输入:no-cache。使用 no-cache 表示每次请求独立返回,不输入则相同查询词会缓存 10 分钟 |
请求体参数
| 参数 | 必填 | 类型 | 描述 |
|---|---|---|---|
| q | Y | String | 搜索查询词,不可为空 |
| count | N | Short | 返回结果数量(默认 10,最大 50) 枚举:10 / 20 / 30 / 40 / 50 |
| freshness | N | String | 按时间范围筛选:Day / Week / Month |
| offset | N | Short | 分页偏移量,从 0 开始。默认 0。偏移过大可能返回空结果 |
| enableContent | N | Bool | 控制是否返回长摘要 true:返回 false:不返回(默认) |
| contentType | N | String | 长摘要格式(需 enableContent = true)HTML / MARKDOWN / TEXT(默认) |
| contentTimeout | N | Float | 长摘要读取超时秒数(默认 3 秒,仅 enableContent = true 时生效) |
| mainText | N | Bool | 是否返回关键片段(需 enableContent = true) true:返回 false:默认 |
返回值说明
| 字段 | 类型 | 描述 |
|---|---|---|
| queryContext.originalQuery | String | 用户的原始搜索词 |
| webPages.value | Array | 搜索结果列表 |
| webPages.value.name | String | 网页标题 |
| webPages.value.url | String | 网页 URL |
| webPages.value.datePublished | String | 页面发布时间,部分网站包含 示例: 2025-07-14T01:15:00.0000000Z |
| webPages.value.snippet | String | 文本短摘要 |
| webPages.value.mainText | String | 智能关键片段,比 snippet 更智能 |
| webPages.value.siteName | String | 网站名称(部分包含) |
| webPages.value.contentCrawled | Bool | 长摘要读取状态:true 成功 / false 失败 |
| webPages.value.content | String | 网页长摘要内容(来自正文) |
| webPages.value.logo | String | 网站 logo(部分包含) |
| webPages.value.imageList | Array | 网页中的图片列表(部分包含) |
| webPages.value.score | Float | 内容相关性分数 |
请求示例
cURL
curl --location --request GET 'https://{basePath}/search/{endpoint}/smart?q=cat&count=10&mainText=true&enableContent=true' \
--header 'Authorization: Bearer {AK}' \
--header 'pragma: no-cache'
Python(Requests)
import requests
BasePath = 'xxxxxx' # 请替换为您获取到的 BasePath
Endpoint = 'xxxxxx' # 请替换为您获取到的 Endpoint
AK = 'xxxxxx' # 请替换为您获取到的 AK
url = f"https://{BasePath}/search/{Endpoint}/smart"
payload = {
"q": "cat",
"count": 10,
"enableContent": True,
"mainText": True
}
headers = {
'Authorization': f'Bearer {AK}',
'Pragma': 'no-cache'
}
response = requests.get(url, headers=headers, params=payload)
print(response.text)
返回示例(部分)
{
"queryContext": {
"originalQuery": "cat"
},
"webPages": {
"value": [
{
"name": "cat - 搜狗百科",
"url": "http://baike.sogou.com/v64497242.htm?fromTitle=cat",
"datePublished": "2024-07-31T06:25:29.0000000",
"snippet": "cat(英[kæt],美[kæt]),英语单词...",
"siteName": "搜狗百科",
"content": "cat(英[kæt],美[kæt]),英语单词...",
"contentCrawled": "true",
"logo": "http://search.sogoucdn.com/baike/common/favicon.d5e2980b.ico",
"score": 0.6703299,
"imageList": [],
"mainText": "短语搭配为 pet cat..."
}
]
}
}
状态码说明
| 状态码 | 错误码 | 描述 |
|---|---|---|
| 200 | - | 接口调用成功 |
| 429 | - | qps 超限,需要联系工作人员提升额度 |