关键词搜索
按关键词搜索知乎,可选的搜索结果类型、排序、时间间隔、话题显示和偏移量控制。用于查找相关的回答、文章或视频。
参数
| 参数 | 必填 | 类型 | 说明 | 示例 | 可选值 |
|---|---|---|---|---|---|
keyword |
必填 | string | 搜索关键词。 | 咖啡 |
— |
offset |
可选 | integer | 起始偏移量,从0开始。 | 0 |
— |
show_all_topics |
可选 | string | 是否显示所有话题。 可选值: - `FALSE`: 不显示话题。 - `TRUE`: 显示所有话题。 | FALSE |
FALSETRUE |
vertical |
可选 | string | 结果类型筛选。 可选值: - `answer`: 仅回答。 - `article`: 仅文章。 - `zvideo`: 仅视频。 | answer |
answerarticlezvideo |
sort |
可选 | string | 排序条件。 可选值: - `upvoted_count`: 最多点赞。 - `created_time`: 最新发布。 | upvoted_count |
upvoted_countcreated_time |
time_interval |
可选 | string | 发布时间间隔筛选。 可选值: - `a_day`: 一天内。 - `a_week`: 一周内。 - `a_month`: 一个月内。 - `three_months`: 三个月内。 - `half_a_year`: 半年内。 - `a_year`: 一年内。 | a_day |
a_daya_weeka_monththree_monthshalf_a_yeara_year |
代码示例
curl -G "https://api.mofa-ai.com/v1/zhihu/search_v1" \
-H "Authorization: Bearer $MOFA_API_KEY" \
--data-urlencode 'keyword=咖啡' \
--data-urlencode 'offset=0' \
--data-urlencode 'show_all_topics=FALSE' \
--data-urlencode 'vertical=answer' \
--data-urlencode 'sort=upvoted_count' \
--data-urlencode 'time_interval=a_day'
import os
import requests
resp = requests.get(
"https://api.mofa-ai.com/v1/zhihu/search_v1",
headers={"Authorization": f"Bearer {os.environ['MOFA_API_KEY']}"},
params={
"keyword": "咖啡",
"offset": "0",
"show_all_topics": "FALSE",
"vertical": "answer",
"sort": "upvoted_count",
"time_interval": "a_day",
},
timeout=60,
)
body = resp.json()
if body["success"]:
print(body["cost_usd"], body["data"])
else:
print(body["error"], body["message"])
const url = new URL("https://api.mofa-ai.com/v1/zhihu/search_v1");
url.search = new URLSearchParams({
keyword: "咖啡",
offset: "0",
show_all_topics: "FALSE",
vertical: "answer",
sort: "upvoted_count",
time_interval: "a_day",
});
const resp = await fetch(url, {
headers: { Authorization: `Bearer ${process.env.MOFA_API_KEY}` },
});
const body = await resp.json();
if (body.success) console.log(body.cost_usd, body.data);
else console.error(body.error, body.message);
在线试用
登录后可以在这里直接调用此接口,按价格从余额扣费,失败不收费。新账户赠送 $0.50 试用额度。
响应示例
这个接口暂无响应示例。