一个基于 Netlify Functions 的多搜索引擎聚合 API,支持 Bing、Yahoo 和知乎搜索。
https://incredible-bonbon-8786a7.netlify.app/.netlify/functions/search
参数 | 类型 | 必填 | 说明 | 示例 |
---|---|---|---|---|
q | string | 是 | 搜索关键词 | javascript教程 |
engines | string | 否 | 搜索引擎,多个用逗号分隔,默认为 bing,yahoo,zhihu | bing 或 yahoo 或 zhihu 或 bing,yahoo,zhihu |
# 使用所有搜索引擎
curl "https://incredible-bonbon-8786a7.netlify.app/.netlify/functions/search?q=javascript教程"
# 仅使用知乎搜索
curl "https://incredible-bonbon-8786a7.netlify.app/.netlify/functions/search?q=javascript教程&engines=zhihu"
{
"status": "success",
"data": {
"keyword": "javascript教程",
"engines": ["bing", "yahoo", "zhihu"],
"results": [
{
"title": "搜索结果标题",
"link": "https://example.com",
"description": "搜索结果描述",
"source": "bing"
},
{
"title": "知乎问题标题",
"link": "https://www.zhihu.com/question/xxx",
"description": "回答内容",
"author": "回答者",
"source": "zhihu"
}
],
"total_found": 10
}
}
{
"status": "error",
"message": "错误信息"
}
- 克隆仓库
git clone https://github.com/luoluoluo22/baidu-search-api.git
cd baidu-search-api
- 安装依赖
yarn install
- 配置环境变量
创建
.env
文件并添加以下配置:
ZHIHU_COOKIE="你的知乎Cookie"
注意:知乎Cookie需要登录知乎后从浏览器开发者工具中获取。
- 启动开发服务器
yarn dev
- Fork 这个仓库
- 在 Netlify 中创建新项目并连接到你的 Fork
- 在 Netlify 的环境变量设置中添加
ZHIHU_COOKIE
- 部署完成后即可使用
- Netlify Functions
- Node.js
- Cheerio (网页解析)
- Node-fetch (网络请求)
MIT