Skip to content

基于Selenium的百度搜索API,支持Netlify Serverless部署

Notifications You must be signed in to change notification settings

luoluoluo22/baidu-search-api

Repository files navigation

多引擎搜索 API

一个基于 Netlify Functions 的多搜索引擎聚合 API,支持 Bing、Yahoo 和知乎搜索。

API 使用方法

接口地址

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": "错误信息"
}

本地开发

  1. 克隆仓库
git clone https://github.com/luoluoluo22/baidu-search-api.git
cd baidu-search-api
  1. 安装依赖
yarn install
  1. 配置环境变量 创建 .env 文件并添加以下配置:
ZHIHU_COOKIE="你的知乎Cookie"

注意:知乎Cookie需要登录知乎后从浏览器开发者工具中获取。

  1. 启动开发服务器
yarn dev

部署

  1. Fork 这个仓库
  2. 在 Netlify 中创建新项目并连接到你的 Fork
  3. 在 Netlify 的环境变量设置中添加 ZHIHU_COOKIE
  4. 部署完成后即可使用

技术栈

  • Netlify Functions
  • Node.js
  • Cheerio (网页解析)
  • Node-fetch (网络请求)

许可证

MIT

About

基于Selenium的百度搜索API,支持Netlify Serverless部署

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published