bdsearch

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

bdsearch

bdsearch

封装
bdsearch
命令行工具,用于百度网页搜索。
Encapsulates the
bdsearch
command-line tool for Baidu web search.

核心能力

Core Capabilities

  1. 网页搜索 - 查询公开网页与资讯内容
  2. 时间过滤 - 支持最近一天、一周、一月、一年或自定义日期范围
  3. 多格式输出 - 支持 JSON、Markdown、表格
  4. 配置管理 - 支持 API Key 配置与默认参数管理
  1. Web Search - Query public web pages and news content
  2. Time Filtering - Supports the latest day, week, month, year, or custom date range
  3. Multi-format Output - Supports JSON, Markdown, and table formats
  4. Configuration Management - Supports API Key configuration and default parameter management

工作流程

Workflow

🔍 执行网页搜索

🔍 Execute Web Search

当用户表达搜索、查资料、查新闻、做调研意图时,尝试执行如下搜索命令:
bash
bdsearch "关键词" --format json --count 10
视需要也可以使用如下常见用法:
bash
bdsearch "人工智能" --count 10 --format json  # 搜索关键词,返回前10条结果,格式为JSON
bdsearch "最新新闻" --freshness pd --format json # 搜索最近一天的新闻,格式为JSON 
bdsearch "科技新闻" --freshness "2025-09-01to2025-09-08" --format markdown  # 搜索指定日期范围的新闻,格式为Markdown
When users express intentions of searching, looking up information, checking news, or conducting research, try executing the following search command:
bash
bdsearch "关键词" --format json --count 10
Common usages can also be applied as needed:
bash
bdsearch "人工智能" --count 10 --format json  # Search keywords, return top 10 results in JSON format
bdsearch "最新新闻" --freshness pd --format json # Search news from the latest day in JSON format
bdsearch "科技新闻" --freshness "2025-09-01to2025-09-08" --format markdown  # Search news within the specified date range in Markdown format

🛠️ 错误排查

🛠️ Troubleshooting

如果执行失败,首先检查是否安装
bdsearch
,以及是否正确配置了百度 API Key。可以按照以下步骤进行排查:
1. 检查安装 → 2. 检查认证配置 
Step 1: 检查是否安装 bdsearch
bash
command -v bdsearch
如果未安装,执行:
bash
npm install -g @lyhue1991/bdsearch
Step 2: 检查认证配置
检查本地配置:
bash
bdsearch config --show
如果未配置,检查环境变量:
bash
printenv BAIDU_API_KEY
如果仍然未配置,则需要用户提供百度 API Key,然后执行:
bash
bdsearch config --api-key "你的APIKey"
If execution fails, first check if
bdsearch
is installed and if the Baidu API Key is configured correctly. Follow these steps for troubleshooting:
1. Check Installation → 2. Check Authentication Configuration
Step 1: Check if bdsearch is installed
bash
command -v bdsearch
If not installed, execute:
bash
npm install -g @lyhue1991/bdsearch
Step 2: Check Authentication Configuration
Check local configuration:
bash
bdsearch config --show
If not configured, check environment variables:
bash
printenv BAIDU_API_KEY
If still not configured, ask the user for the Baidu API Key and execute:
bash
bdsearch config --api-key "你的APIKey"

⚙️ 配置 bdsearch

⚙️ Configure bdsearch

当用户只需配置 API Key 或默认参数时:
bash
bdsearch config --api-key "你的APIKey"
bdsearch config --default-format json --default-count 10 --default-freshness pd
查看当前配置:
bash
bdsearch config --show
重置配置:
bash
bdsearch config --reset
When users only need to configure the API Key or default parameters:
bash
bdsearch config --api-key "你的APIKey"
bdsearch config --default-format json --default-count 10 --default-freshness pd
View current configuration:
bash
bdsearch config --show
Reset configuration:
bash
bdsearch config --reset

📰 查询最近内容

📰 Query Latest Content

当用户明确要“最新”“最近几天”“本周”的内容时,优先使用时间过滤:
bash
bdsearch "AI 新闻" --freshness pd --format json
bdsearch "大模型进展" --freshness pw --format json
When users explicitly request "latest", "recent days", or "this week" content, prioritize using time filtering:
bash
bdsearch "AI 新闻" --freshness pd --format json
bdsearch "大模型进展" --freshness pw --format json

📄 输出适合阅读的结果

📄 Output Reader-friendly Results

当用户需要直接阅读或复制结果时:
bash
bdsearch "Node.js" --format markdown
bdsearch "Python" --count 10 --format table
When users need results for direct reading or copying:
bash
bdsearch "Node.js" --format markdown
bdsearch "Python" --count 10 --format table

参数说明

Parameter Description

参数说明
query
搜索关键词,必填
--count <number>
返回结果数量,范围 1-50,默认 10
--freshness <value>
时间过滤,支持
pd
pw
pm
py
YYYY-MM-DDtoYYYY-MM-DD
--format <format>
输出格式,支持
json
markdown
table
ParameterDescription
query
Search keyword, required
--count <number>
Number of returned results, range 1-50, default 10
--freshness <value>
Time filtering, supports
pd
,
pw
,
pm
,
py
or
YYYY-MM-DDtoYYYY-MM-DD
--format <format>
Output format, supports
json
,
markdown
,
table

注意事项

Notes

  1. 优先用 JSON - 需要进一步分析、提取字段、总结内容时,优先使用
    --format json
  2. 认证要求 - 使用前必须配置
    BAIDU_API_KEY
    ,或通过
    bdsearch config --api-key
    保存本地配置
  3. 结果可能重复 - 上游接口可能返回重复链接,必要时需要按
    url
    去重
  4. 时间过滤建议 - 查询新闻或动态信息时,优先增加
    --freshness
  1. Prioritize JSON - When further analysis, field extraction, or content summarization is needed, prioritize using
    --format json
  2. Authentication Requirement - Must configure
    BAIDU_API_KEY
    before use, or save local configuration via
    bdsearch config --api-key
  3. Possible Duplicate Results - The upstream interface may return duplicate links; deduplication by
    url
    is necessary if needed
  4. Time Filtering Suggestion - Prioritize adding
    --freshness
    when querying news or dynamic information

快速参考

Quick Reference

bash
undefined
bash
undefined

查看帮助

View help

bdsearch --help bdsearch config --help
bdsearch --help bdsearch config --help

查看配置

View configuration

bdsearch config --show
bdsearch config --show

设置 API Key

Set API Key

bdsearch config --api-key "你的APIKey"
bdsearch config --api-key "你的APIKey"

基础搜索

Basic search

bdsearch "人工智能" --format json
bdsearch "人工智能" --format json

指定结果数量

Specify number of results

bdsearch "TypeScript 教程" --count 5 --format json
bdsearch "TypeScript 教程" --count 5 --format json

查询最近内容

Query latest content

bdsearch "最新新闻" --freshness pd --format json
bdsearch "最新新闻" --freshness pd --format json

自定义日期范围

Custom date range

bdsearch "科技新闻" --freshness "2025-09-01to2025-09-08" --format json
bdsearch "科技新闻" --freshness "2025-09-01to2025-09-08" --format json

适合阅读的输出

Reader-friendly output

bdsearch "Node.js" --format markdown bdsearch "Python" --format table
undefined
bdsearch "Node.js" --format markdown bdsearch "Python" --format table
undefined