Web Search

基于DuckDuckGo API的多类型网络搜索技能,支持文本、新闻、图片和视频检索。

已扫描
适合谁
研究人员、内容创作者
不适合谁
需要高精度搜索引擎的用户、依赖特定平台API的开发者
国内可用性
需网络配置。可能需要网络配置或第三方服务可访问。
安装难度
新手友好(★☆☆)。基于终端操作、依赖、API Key 和本地环境要求的初步判断。

安装与下载

openclaw skills install @billyutw/web-search

Skill 说明

命令、参数、文件名以原文为准

Web Search

概述

使用 DuckDuckGo 的 API 搜索网页,获取跨网页、新闻文章、图片和视频的信息。支持多种返回格式(文本、Markdown、JSON),并提供时间范围、地区和安全搜索等筛选选项。

何时使用此技能

当用户提出以下请求时,请使用此技能:

  • 在线查找信息或资源
  • 获取当前或近期的网络信息
  • 查找特定主题的新闻文章
  • 根据描述或主题搜索图片
  • 查找特定主题的视频
  • 需要基于最新网络数据的研究
  • 使用网络来源进行事实核查或验证
  • 收集某个主题的链接和资源

前置条件

安装所需依赖:

pip install duckduckgo-search

该库提供了对 DuckDuckGo 搜索 API 的简单 Python 接口,无需 API 密钥或身份验证。

核心功能

1. 基础网页搜索

搜索网页和相关信息:

python scripts/search.py "<查询>"

示例:

python scripts/search.py "python asyncio 教程"

返回前 10 个网页结果,包含标题、URL 和描述,以清晰的文本格式呈现。

2. 限制结果数量

控制返回的结果数量:

python scripts/search.py "<查询>" --max-results <N>

示例:

python scripts/search.py "机器学习框架" --max-results 20

适用场景:

  • 获取更全面的结果(提高上限)
  • 快速查看少量结果(降低上限)
  • 平衡详细程度与处理时间

3. 时间范围筛选

按时效性过滤结果:

python scripts/search.py "<查询>" --time-range <d|w|m|y>

时间范围选项:

  • d - 近一天
  • w - 近一周
  • m - 近一月
  • y - 近一年

示例:

python scripts/search.py "人工智能新闻" --time-range w

适用于:

  • 查找最新新闻或更新
  • 过滤过时内容
  • 跟踪最新进展

4. 新闻搜索

专门搜索新闻文章:

python scripts/search.py "<查询>" --type news

示例:

python scripts/search.py "气候变化" --type news --time-range w --max-results 15

新闻结果包含:

  • 文章标题
  • 发布媒体
  • 发布日期
  • URL
  • 文章摘要/描述

5. 图片搜索

搜索图片:

python scripts/search.py "<查询>" --type images

示例:

python scripts/search.py "山间日落" --type images --max-results 20

图片筛选选项:

尺寸筛选:

python scripts/search.py "风景照片" --type images --image-size Large

选项:SmallMediumLargeWallpaper

颜色筛选:

python scripts/search.py "抽象艺术" --type images --image-color Blue

选项:colorMonochromeRedOrangeYellowGreenBluePurplePinkBrownBlackGrayTealWhite

类型筛选:

python scripts/search.py "图标" --type images --image-type transparent

选项:photoclipartgiftransparentline

布局筛选:

python scripts/search.py "壁纸" --type images --image-layout Wide

选项:SquareTallWide

图片结果包含:

  • 图片标题
  • 图片 URL(直接指向图片的链接)
  • 缩略图 URL
  • 来源网站
  • 尺寸(宽 × 高)

6. 视频搜索

搜索视频:

python scripts/search.py "<查询>" --type videos

示例:

python scripts/search.py "python 教程" --type videos --max-results 15

视频筛选选项:

时长筛选:

python scripts/search.py "烹饪食谱" --type videos --video-duration short

选项:shortmediumlong

分辨率筛选:

python scripts/search.py "纪录片" --type videos --video-resolution high

选项:highstandard

视频结果包含:

  • 视频标题
  • 发布者/频道
  • 时长
  • 发布日期
  • 视频 URL
  • 描述

7. 区域特定搜索

进行区域化搜索结果:

python scripts/search.py "<查询>" --region <地区代码>

常见地区代码:

  • us-en - 美国(英语)
  • uk-en - 英国(英语)
  • ca-en - 加拿大(英语)
  • au-en - 澳大利亚(英语)
  • de-de - 德国(德语)
  • fr-fr - 法国(法语)
  • wt-wt - 全球(默认)

示例:

python scripts/search.py "本地新闻" --region us-en --type news

8. 安全搜索控制

控制安全搜索过滤:

python scripts/search.py "<查询>" --safe-search <on|moderate|off>

选项:

  • on - 严格过滤
  • moderate - 平衡过滤(默认)
  • off - 不过滤

示例:

python scripts/search.py "医学信息" --safe-search on

9. 输出格式选择

选择结果的输出格式:

文本格式(默认):

python scripts/search.py "量子计算"

以编号列表形式展示的干净可读纯文本。

Markdown 格式:

python scripts/search.py "量子计算" --format markdown

带标题、加粗和链接的格式化 Markdown。

JSON 格式:

python scripts/search.py "量子计算" --format json

结构化的 JSON 数据,便于程序处理。

10. 将结果保存到文件

将搜索结果保存到文件中:

python scripts/search.py "<查询>" --output <文件路径>

示例:

python scripts/search.py "人工智能" --output ai_results.txt
python scripts/search.py "AI 新闻" --type news --format markdown --output ai_news.md
python scripts/search.py "AI 研究" --format json --output ai_data.json

文件格式由 --format 参数决定,而非文件扩展名。

输出格式示例

文本格式

1. 页面标题示例
   URL: https://example.com/page
   页面内容的简要描述...

2. 另一个结果
   URL: https://example.com/another
   另一个描述...

Markdown 格式

## 1. 页面标题示例

**URL:** https://example.com/page

页面内容的简要描述...

## 2. 另一个结果

**URL:** https://example.com/another

另一个描述...

JSON 格式

[
  {
    "title": "页面标题示例",
    "href": "https://example.com/page",
    "body": "页面内容的简要描述..."
  },
  {
    "title": "另一个结果",
    "href": "https://example.com/another",
    "body": "另一个描述..."
  }
]

常见使用场景

主题研究

获取某个主题的全面信息:

# 从网页获取概览
python scripts/search.py "机器学习基础" --max-results 15 --output ml_web.txt

# 获取最新新闻
python scripts/search.py "机器学习" --type news --time-range m --output ml_news.txt

# 查找教程视频
python scripts/search.py "机器学习教程" --type videos --max-results 10 --output ml_videos.txt

实时事件监控

跟踪特定主题的新闻动态:

python scripts/search.py "气候峰会" --type news --time-range d --format markdown --output daily_climate_news.md

寻找视觉资源

按特定条件搜索图片:

python scripts/search.py "数据可视化示例" --type images --image-type photo --image-size Large --max-results 25 --output viz_images.txt

事实核查

通过近期来源验证信息:

python scripts/search.py "待核实的具体说法" --time-range w --max-results 20

学术研究

查找学术相关主题的资料:

python scripts/search.py "量子纠缠研究" --time-range y --max-results 30 --output quantum_research.txt

市场调研

收集产品或公司相关信息:

python scripts/search.py "2025年电动汽车市场" --max-results 20 --format markdown --output ev_market.md
python scripts/search.py "电动汽车新闻" --type news --time-range m --output ev_news.txt

实现方法

当用户请求网络搜索时:

  1. 识别搜索意图

- 内容类型(网页、新闻、图片、视频)?

- 结果需要多新?

- 需要多少条结果?

- 是否有筛选要求?

  1. 配置搜索参数

- 选择合适的搜索类型(--type

- 若时效性重要,设置时间范围(--time-range

- 调整结果数量(--max-results

- 应用过滤条件(图片尺寸、视频时长等)

  1. 选择输出格式

- 文本格式适合快速阅读

- Markdown 格式适合文档编写

- JSON 格式便于后续处理

  1. 执行搜索

- 运行搜索命令

- 如需保存结果,指定文件路径

- 直接输出到标准输出供即时查看

  1. 处理结果

- 如需读取已保存文件

- 提取 URL 或特定信息

- 合并多个搜索的结果

快速参考

命令结构:

python scripts/search.py "<查询内容>" [选项]

核心选项:

  • -t, --type - 搜索类型(web、news、images、videos)
  • -n, --max-results - 最大结果数(默认值:10)
  • --time-range - 时间筛选(d、w、m、y)
  • -r, --region - 区域代码(如:us-en、uk-en)
  • --safe-search - 安全搜索级别(on、moderate、off)
  • -f, --format - 输出格式(text、markdown、json)
  • -o, --output - 保存至文件

图片专用选项:

  • --image-size - 尺寸筛选(Small、Medium、Large、Wallpaper)
  • --image-color - 颜色筛选
  • --image-type - 类型筛选(photo、clipart、gif、transparent、line)
  • --image-layout - 布局筛选(Square、Tall、Wide)

视频专用选项:

  • --video-duration - 时长筛选(short、medium、long)
  • --video-resolution - 分辨率筛选(high、standard)

获取完整帮助:

python scripts/search.py --help

最佳实践

  1. 保持具体 - 使用清晰明确的搜索词以获得更好结果
  2. 使用时间筛选 - 通过 --time-range 获取最新信息
  3. 调整结果数量 - 初始可设为 10–20 条,必要时增加
  4. 保存重要搜索 - 使用 --output 保留结果
  5. 选择合适类型 - 当前事件用新闻搜索,一般信息用网页搜索
  6. 使用 JSON 用于自动化 - JSON 格式最易程序解析
  7. 合理使用 - 不要频繁重复发起大量搜索请求

故障排除

常见问题:

  • “缺少必需依赖”:运行 pip install duckduckgo-search
  • 未找到结果:尝试扩大搜索词范围或移除时间筛选
  • 超时错误:搜索服务可能暂时不可用;稍后重试
  • 速率限制:若频繁请求,请间隔发送
  • 结果不符合预期:DuckDuckGo 的结果与 Google 可能不同;建议优化查询词

局限性:

  • 结果质量取决于 DuckDuckGo 的索引和算法
  • 不支持高级搜索语法(如 Google 的 site:、filetype: 等)
  • 图片和视频搜索结果数量通常少于网页搜索
  • 无法控制结果排序或相关性评分
  • 某些专业搜索在专用搜索引擎中表现更优

高级应用场景

多类型搜索组合

通过组合多种搜索类型获取全面信息:

# 网页概览
python scripts/search.py "主题" --max-results 15 --output topic_web.txt

# 最新新闻
python scripts/search.py "主题" --type news --time-range w --output topic_news.txt

# 图片资源
python scripts/search.py "主题" --type images --max-results 20 --output topic_images.txt

程序化处理

使用 JSON 输出进行自动化处理:

python scripts/search.py "研究主题" --format json --output results.json
# 然后使用另一个脚本处理结果
python analyze_results.py results.json

构建知识库

从网络搜索结果生成可检索的文档:

# 搜索多个相关主题
python scripts/search.py "主题1" --format markdown --output kb/主题1.md
python scripts/search.py "主题2" --format markdown --output kb/主题2.md
python scripts/search.py "主题3" --format markdown --output kb/主题3.md

资源

scripts/search.py

主搜索工具,实现 DuckDuckGo 搜索功能。主要特性:

  • 多种搜索类型 - 网页、新闻、图片和视频
  • 灵活的筛选条件 - 时间范围、地区、安全搜索以及特定类型过滤
  • 多种输出格式 - 文本、Markdown 和 JSON
  • 文件输出 - 将结果保存以供后续处理
  • 清晰的格式化 - 人类可读的输出,包含所有关键信息
  • 错误处理 - 对网络错误和空结果进行优雅处理

该脚本可直接执行,并通过 --help 提供完整的命令行帮助。

B
@billyutw

已收录 1 个 Skill

相关推荐