brave-search

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Brave Search

Brave Search

Web search and content extraction using the official Brave Search API. No browser required.
通过官方Brave Search API实现网页搜索与内容提取,无需浏览器。

Setup

配置步骤

Requires a Brave Search API account with a free subscription. A credit card is required to create the free subscription (you won't be charged).
  1. Create an account at https://api-dashboard.search.brave.com/register
  2. Create a "Free AI" subscription
  3. Create an API key for the subscription
  4. Add to your shell profile (
    ~/.profile
    or
    ~/.zprofile
    for zsh):
    bash
    export BRAVE_API_KEY="your-api-key-here"
  5. Install dependencies (run once):
    bash
    cd {baseDir}
    npm install
需要拥有一个带有免费订阅的Brave Search API账户。创建免费订阅需提供信用卡信息,但不会产生扣费。
  1. https://api-dashboard.search.brave.com/register创建账户
  2. 创建“Free AI”订阅
  3. 为该订阅生成API密钥
  4. 将密钥添加到你的Shell配置文件中(zsh用户为~/.profile或~/.zprofile):
    bash
    export BRAVE_API_KEY="your-api-key-here"
  5. 安装依赖(只需运行一次):
    bash
    cd {baseDir}
    npm install

Search

搜索功能

bash
{baseDir}/search.js "query"                         # Basic search (5 results)
{baseDir}/search.js "query" -n 10                   # More results (max 20)
{baseDir}/search.js "query" --content               # Include page content as markdown
{baseDir}/search.js "query" --freshness pw          # Results from last week
{baseDir}/search.js "query" --freshness 2024-01-01to2024-06-30  # Date range
{baseDir}/search.js "query" --country DE            # Results from Germany
{baseDir}/search.js "query" -n 3 --content          # Combined options
bash
{baseDir}/search.js "query"                         # 基础搜索(返回5条结果)
{baseDir}/search.js "query" -n 10                   # 更多结果(最多20条)
{baseDir}/search.js "query" --content               # 包含以markdown格式呈现的页面内容
{baseDir}/search.js "query" --freshness pw          # 返回过去一周的结果
{baseDir}/search.js "query" --freshness 2024-01-01to2024-06-30  # 自定义日期范围结果
{baseDir}/search.js "query" -n 3 --content          # 组合选项使用

Options

可选参数

  • -n <num>
    - Number of results (default: 5, max: 20)
  • --content
    - Fetch and include page content as markdown
  • --country <code>
    - Two-letter country code (default: US)
  • --freshness <period>
    - Filter by time:
    • pd
      - Past day (24 hours)
    • pw
      - Past week
    • pm
      - Past month
    • py
      - Past year
    • YYYY-MM-DDtoYYYY-MM-DD
      - Custom date range
  • -n <num>
    - 结果数量(默认:5,最大值:20)
  • --content
    - 获取并包含以markdown格式呈现的页面内容
  • --country <code>
    - 两位字母的国家代码(默认:US)
  • --freshness <period>
    - 按时间过滤结果:
    • pd
      - 过去24小时
    • pw
      - 过去一周
    • pm
      - 过去一个月
    • py
      - 过去一年
    • YYYY-MM-DDtoYYYY-MM-DD
      - 自定义日期范围

Extract Page Content

提取页面内容

bash
{baseDir}/content.js https://example.com/article
Fetches a URL and extracts readable content as markdown.
bash
{baseDir}/content.js https://example.com/article
获取指定URL并提取可读内容,以markdown格式输出。

Output Format

输出格式

--- Result 1 ---
Title: Page Title
Link: https://example.com/page
Age: 2 days ago
Snippet: Description from search results
Content: (if --content flag used)
  Markdown content extracted from the page...

--- Result 2 ---
...
--- Result 1 ---
Title: 页面标题
Link: https://example.com/page
Age: 2天前
Snippet: 搜索结果中的描述内容
Content: (当使用--content参数时显示)
  从页面提取的Markdown内容...

--- Result 2 ---
...

When to Use

使用场景

  • Searching for documentation or API references
  • Looking up facts or current information
  • Fetching content from specific URLs
  • Any task requiring web search without interactive browsing
  • 搜索文档或API参考资料
  • 查询事实信息或最新资讯
  • 从特定URL获取内容
  • 任何无需交互式浏览的网页搜索任务