Web Search
Free web search using DuckDuckGo's Instant Answer API. No API key required.
Quick Start
CODEBLOCK0
Command-Line Options
Core Options
- -
-h, --help - Display help message with usage examples - INLINECODE1 - Output format:
text, markdown, plain (default: text)
-
text: Colored terminal output (default)
-
markdown: Clean markdown format (no ANSI colors)
-
plain: Plain text without colors
- -
--no-color - Disable colored output (same as --format plain) - INLINECODE11 - Control number of related topics to show (default: 5)
- INLINECODE12 - Minimal output mode (just results, no headers/footer)
Output to File
Use shell redirection to save results to file:
CODEBLOCK1
What It Returns
The tool provides several result types:
- - Answers - Direct answers for calculations, conversions, weather, etc.
- Abstracts - Wikipedia-style summaries with source and URL
- Definitions - Word/term definitions
- Related Topics - Additional relevant results (configurable, 5 default)
Best Practices
- 1. Be specific - More specific queries get better instant answers
- Try variations - If no results, rephrase your query
- Use for facts - Definitions, calculations, quick lookups work best
- Check URL - Always provides DuckDuckGo link for full search
- Use appropriate format:
- Terminal output:
--format text (colored, default)
- Documentation:
--format markdown > file.md
- Logs/piping: --format plain
or --no-color
## Limitations
- No full web search results (only instant answers)
- Some queries return limited results depending on DuckDuckGo's data
- Character encoding issues in some abstracts (known limitation)
- Requires internet access to query DuckDuckGo API
- Not all query types return instant answers (e.g., complex math like sqrt(144)
)
- Definitions may not always be available for all terms
- Recent news may not appear (DuckDuckGo focuses on evergreen content)
## Usage Examples
### Basic Search
CODEBLOCK2
### Markdown Format
CODEBLOCK3
### Plain/No Color
CODEBLOCK4
### Control Related Topics
CODEBLOCK5
### Quiet Mode
CODEBLOCK6
### Combined Options
CODEBLOCK7
## Tested Scenarios
Tested and verified to work:
- ✅ Calculations: 2+2
, 10% of 500
- ✅ Conversions: 100 miles to km
- ✅ Wikipedia queries: what is artificial intelligence
- ✅ Programming: what is python
, how to install docker
- ✅ People: who is Elon Musk
- ✅ Scientific facts: speed of light
- ✅ Weather: weather in Tokyo
- ✅ Edge cases: empty queries, special characters, no results
- ✅ Output formats: text, markdown, plain
- ✅ Flags: --help, --format, --no-color, --max-related, --quiet
See [test-outputs.md](test-outputs.md) for detailed test results.
## Troubleshooting
### "No direct results found"
Try rephasing your query or using the provided DuckDuckGo URL for full search.
### Network errors
Check internet connection. Tool requires network access.
### Character encoding issues
Some abstracts display garbled characters. This is a known issue with basic parsing (install jq
for better results).
### "jq not found" warning
The tool works without jq
using basic text extraction, but installing jq
improves JSON parsing:
CODEBLOCK8
## Output Format
### Text Format (default)
- **Blue** - Headers and search info
- **Green** - Result markers and content
- **Yellow** - Sources, URLs, and warnings
- **Red** - Errors
Use --format plain
or --no-color
to disable colors.
### Markdown Format
Clean markdown with:
- ##
headers for sections
- bold for emphasis
- -
bullet lists
- italics for metadata
- [links]()
for URLs
### Plain Format
No ANSI codes or markdown formatting - suitable for logs and piping.
## Requirements
- curl
or wget
(for HTTP requests)
- Optional: jq` (for better JSON parsing)
网络搜索
使用DuckDuckGo的即时答案API进行免费网络搜索。无需API密钥。
快速开始
bash
基础搜索
cd /home/hxx/clawd/tools && ./web-search.sh 你的查询
示例
./web-search.sh 什么是人工智能
./web-search.sh Python编程
./web-search.sh 定义递归
./web-search.sh 2+2
命令行选项
核心选项
- - -h, --help - 显示包含使用示例的帮助信息
- --format <格式> - 输出格式:text、markdown、plain(默认:text)
- text:彩色终端输出(默认)
- markdown:干净的Markdown格式(无ANSI颜色)
- plain:无颜色的纯文本
- - --no-color - 禁用彩色输出(等同于--format plain)
- --max-related - 控制显示的相关主题数量(默认:5)
- --quiet - 最小输出模式(仅结果,无页眉/页脚)
输出到文件
使用Shell重定向将结果保存到文件:
bash
保存到文件
./web-search.sh 查询 > output.txt
使用Markdown格式
./web-search.sh --format markdown 查询 > results.md
无颜色输出用于日志
./web-search.sh --no-color 查询 > search.log
返回内容
该工具提供多种结果类型:
- - 答案 - 计算、转换、天气等的直接答案
- 摘要 - 维基百科风格的摘要,包含来源和URL
- 定义 - 单词/术语定义
- 相关主题 - 额外的相关结果(可配置,默认5个)
最佳实践
- 1. 具体明确 - 更具体的查询能获得更好的即时答案
- 尝试变体 - 若无结果,重新表述查询
- 用于事实查询 - 定义、计算、快速查找效果最佳
- 检查URL - 始终提供DuckDuckGo链接用于完整搜索
- 使用合适的格式:
- 终端输出:--format text(彩色,默认)
- 文档:--format markdown > file.md
- 日志/管道:--format plain 或 --no-color
局限性
- - 无完整网页搜索结果(仅即时答案)
- 某些查询返回的结果有限,取决于DuckDuckGo的数据
- 部分摘要存在字符编码问题(已知限制)
- 需要网络访问才能查询DuckDuckGo API
- 并非所有查询类型都返回即时答案(例如,sqrt(144)等复杂数学运算)
- 并非所有术语都能提供定义
- 近期新闻可能不会出现(DuckDuckGo专注于常青内容)
使用示例
基础搜索
bash
简单查询
./web-search.sh 开源AI模型
维基百科风格查询
./web-search.sh 什么是递归
Markdown格式
bash
干净的Markdown输出
./web-search.sh --format markdown Python编程
保存到Markdown文件
./web-search.sh --format markdown AI研究 > research.md
纯文本/无颜色
bash
用于日志或管道
./web-search.sh --format plain 搜索查询
显式禁用颜色
./web-search.sh --no-color 搜索查询
控制相关主题
bash
显示更少相关主题
./web-search.sh --max-related 3 机器学习
显示更多相关主题
./web-search.sh --max-related 10 开源
安静模式
bash
最小输出(仅结果)
./web-search.sh --quiet 42 + 7等于多少
组合选项
bash
Markdown格式,无颜色,保存到文件
./web-search.sh --format markdown --no-color 主题 > results.md
安静模式加自定义相关数量
./web-search.sh --quiet --max-related 2 定义
测试场景
已验证可正常工作的场景:
- - ✅ 计算:2+2、500的10%
- ✅ 转换:100英里转公里
- ✅ 维基百科查询:什么是人工智能
- ✅ 编程:什么是Python、如何安装Docker
- ✅ 人物:埃隆·马斯克是谁
- ✅ 科学事实:光速
- ✅ 天气:东京天气
- ✅ 边界情况:空查询、特殊字符、无结果
- ✅ 输出格式:text、markdown、plain
- ✅ 标志:--help、--format、--no-color、--max-related、--quiet
详细测试结果请参见test-outputs.md。
故障排除
未找到直接结果
尝试重新表述查询,或使用提供的DuckDuckGo URL进行完整搜索。
网络错误
检查网络连接。该工具需要网络访问。
字符编码问题
部分摘要显示乱码。这是基础解析的已知问题(安装jq可获得更好结果)。
未找到jq警告
该工具使用基础文本提取无需jq即可运行,但安装jq可改进JSON解析:
bash
Ubuntu/Debian
sudo apt-get install jq
macOS
brew install jq
通过包管理器
npm install -g jq
输出格式
文本格式(默认)
- - 蓝色 - 页眉和搜索信息
- 绿色 - 结果标记和内容
- 黄色 - 来源、URL和警告
- 红色 - 错误
使用--format plain或--no-color禁用颜色。
Markdown格式
干净的Markdown,包含:
- - ## 章节标题
- 粗体 用于强调
- - 项目符号列表
- 斜体 用于元数据
- [链接]() 用于URL
纯文本格式
无ANSI代码或Markdown格式 - 适用于日志和管道。
要求
- - curl 或 wget(用于HTTP请求)
- 可选:jq(用于更好的JSON解析)