此技能用于搜索网络信息、查找当前内容、查询新闻文章、图片或视频。它通过 DuckDuckGo 搜索 API 以文本、Markdown 或 JSON 格式返回简洁结果,适用于研究、事实核查、获取最新信息或收集网络资源。
Web Search : Overview. 使用 DuckDuckGo 的API搜索网页, 搜索网页中的信息, 搜索新闻文章、 图像和视频是一项面向实际任务的技能,主要用于返回结果有多种格式( 文本、 标记下、 JSON)。它将相关步骤、工具调用和结果整理方式集中到统一流程中,帮助使用者更快完成目标并减少重复操作。
实际使用前应先确认任务范围、数据来源、运行环境、必要权限和关键参数,再依据技能说明逐步执行;若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。
执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;涉及批量任务时,还应保存进度,避免中断后重复操作。
使用 DuckDuckGo 的 API 搜索网络,查找网页、新闻文章、图片和视频中的信息。支持以多种格式(文本、Markdown、JSON)返回结果,并提供时间范围、地区和安全搜索等过滤选项。
当用户提出以下请求时,请使用该技能:
安装所需依赖项:
pip install duckduckgo-search
该库为 DuckDuckGo 搜索 API 提供了一个简洁的 Python 接口,无需 API 密钥或身份认证。
搜索网页与相关信息:
python scripts/search.py ""
示例:
python scripts/search.py "python asyncio tutorial"
以清晰的纯文本格式返回前 10 条网页结果,包含标题、URL 和摘要描述。
控制返回结果的数量:
python scripts/search.py "" --max-results
示例:
python scripts/search.py "machine learning frameworks" --max-results 20
适用场景:
按时效性筛选结果:
python scripts/search.py "" --time-range
时间范围选项:
d — 过去一天w — 过去一周m — 过去一个月y — 过去一年示例:
python scripts/search.py "artificial intelligence news" --time-range w
适用于:
专门搜索新闻文章:
python scripts/search.py "" --type news
示例:
python scripts/search.py "climate change" --type news --time-range w --max-results 15
新闻结果包含:
搜索图片:
python scripts/search.py "" --type images
示例:
python scripts/search.py "sunset over mountains" --type images --max-results 20
图片过滤选项:
尺寸过滤:
python scripts/search.py "landscape photos" --type images --image-size Large
可选值:Small、Medium、Large、Wallpaper
颜色过滤:
python scripts/search.py "abstract art" --type images --image-color Blue
可选值:color、Monochrome、Red、Orange、Yellow、Green、Blue、Purple、Pink、Brown、Black、Gray、Teal、White
类型过滤:
python scripts/search.py "icons" --type images --image-type transparent
可选值:photo、clipart、gif、transparent、line
布局过滤:
python scripts/search.py "wallpapers" --type images --image-layout Wide
可选值:Square、Tall、Wide
图片结果包含:
搜索视频:
python scripts/search.py "" --type videos
示例:
python scripts/search.py "python tutorial" --type videos --max-results 15
视频过滤选项:
时长过滤:
python scripts/search.py "cooking recipes" --type videos --video-duration short
可选值:short、medium、long
分辨率过滤:
python scripts/search.py "documentary" --type videos --video-resolution high
可选值:high、standard
视频结果包含:
按指定地区返回搜索结果:
python scripts/search.py "" --region
常用地区代码:
us-en — 美国(英语)uk-en — 英国(英语)ca-en — 加拿大(英语)au-en — 澳大利亚(英语)de-de — 德国(德语)fr-fr — 法国(法语)wt-wt — 全球(默认)示例:
python scripts/search.py "local news" --region us-en --type news
控制安全搜索过滤强度:
python scripts/search.py "" --safe-search
选项说明:
on — 严格过滤moderate — 平衡过滤(默认)off — 不启用过滤示例:
python scripts/search.py "medical information" --safe-search on
自定义结果输出格式:
文本格式(默认):
python scripts/search.py "quantum computing"
结构清晰、易读的纯文本,带编号结果列表。
Markdown 格式:
python scripts/search.py "quantum computing" --format markdown
格式化 Markdown,含标题、加粗文本及超链接。
JSON 格式:
python scripts/search.py "quantum computing" --format json
结构化 JSON 数据,便于程序化处理。
将搜索结果写入文件:
python scripts/search.py "" --output
示例:
python scripts/search.py "artificial intelligence" --output ai_results.txt python scripts/search.py "AI news" --type news --format markdown --output ai_news.md python scripts/search.py "AI research" --format json --output ai_data.json
实际输出格式由 --format 参数决定,而非文件扩展名。
1. 页面标题示例 URL: https://example.com/page 页面内容简要描述... 2. 另一个结果 URL: https://example.com/another 另一段描述...
## 1. 页面标题示例 **URL:** https://example.com/page 页面内容简要描述... ## 2. 另一个结果 **URL:** https://example.com/another 另一段描述...
[
{
"title": "页面标题示例",
"href": "https://example.com/page",
"body": "页面内容简要描述..."
},
{
"title": "另一个结果",
"href": "https://example.com/another",
"body": "另一段描述..."
}
]
围绕某一主题系统性地收集信息:
# 获取网页概览 python scripts/search.py "machine learning basics" --max-results 15 --output ml_web.txt # 获取近期新闻 python scripts/search.py "machine learning" --type news --time-range m --output ml_news.txt # 查找教学视频 python scripts/search.py "machine learning tutorial" --type videos --max-results 10 --output ml_videos.txt
持续跟踪特定话题的新闻动态:
python scripts/search.py "climate summit" --type news --time-range d --format markdown --output daily_climate_news.md
按具体要求搜索图片:
python scripts/search.py "data visualization examples" --type images --image-type photo --image-size Large --max-results 25 --output viz_images.txt
借助近期信源验证信息真伪:
python scripts/search.py "specific claim to verify" --time-range w --max-results 20
查找学术类主题相关资料:
python scripts/search.py "quantum entanglement research" --time-range y --max-results 30 --output quantum_research.txt
收集产品或公司相关信息:
python scripts/search.py "electric vehicle market 2025" --max-results 20 --format markdown --output ev_market.md python scripts/search.py "EV news" --type news --time-range m --output ev_news.txt
当用户发起网络搜索请求时,按以下步骤执行:
识别搜索意图:
配置搜索参数:
--type)--time-range)--max-results)选择输出格式:
执行搜索:
--output 写入文件处理结果:
命令结构:
python scripts/search.py "" [options]
核心选项:
-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
--time-range--output 保留结果以备复用常见问题:
pip install duckduckgo-search限制说明:
site:、filetype: 等)通过组合不同搜索类型构建全面信息视图:
# 网页概览 python scripts/search.py "topic" --max-results 15 --output topic_web.txt # 近期新闻 python scripts/search.py "topic" --type news --time-range w --output topic_news.txt # 图片资源 python scripts/search.py "topic" --type images --max-results 20 --output topic_images.txt
利用 JSON 输出实现自动化分析:
python scripts/search.py "research topic" --format json --output results.json # 后续交由其他脚本处理 python analyze_results.py results.json
基于网络搜索结果创建可检索的文档知识库:
# 搜索多个关联主题 python scripts/search.py "topic1" --format markdown --output kb/topic1.md python scripts/search.py "topic2" --format markdown --output kb/topic2.md python scripts/search.py "topic3" --format markdown --output kb/topic3.md
主搜索工具,实现了 DuckDuckGo 搜索功能。主要特性包括:
该脚本可直接运行,并内置完整的命令行帮助,可通过 --help 查看。
相关专题
热门下载
相关下载
精品课程
共6课时 | 54.7万人学习
共89课时 | 134.1万人学习
共49课时 | 82.6万人学习