web-search
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWeb Search
网页搜索
Overview
概述
Search the web using DuckDuckGo's API to find information across web pages, news articles, images, and videos. Returns results in multiple formats (text, markdown, JSON) with filtering options for time range, region, and safe search.
通过DuckDuckGo的API搜索网页,查找网页、新闻文章、图片和视频中的信息。支持按时间范围、地区和安全搜索进行过滤,并以多种格式(文本、Markdown、JSON)返回结果。
When to Use This Skill
适用场景
Use this skill when users request:
- Web searches for information or resources
- Finding current or recent information online
- Looking up news articles about specific topics
- Searching for images by description or topic
- Finding videos on specific subjects
- Research requiring current web data
- Fact-checking or verification using web sources
- Gathering URLs and resources on a topic
当用户有以下需求时,可使用该Skill:
- 搜索网页信息或资源
- 查找线上最新资讯
- 查阅特定主题的新闻文章
- 按描述或主题搜索图片
- 查找特定主题的视频
- 需要当前网页数据的研究工作
- 利用网络来源进行事实核查或验证
- 收集特定主题的URL和资源
Prerequisites
前置条件
Install the required dependency:
bash
pip install duckduckgo-searchThis library provides a simple Python interface to DuckDuckGo's search API without requiring API keys or authentication.
安装所需依赖:
bash
pip install duckduckgo-search该库提供了对接DuckDuckGo搜索API的简易Python接口,无需API密钥或身份验证。
Core Capabilities
核心功能
1. Basic Web Search
1. 基础网页搜索
Search for web pages and information:
bash
python scripts/search.py "<query>"Example:
bash
python scripts/search.py "python asyncio tutorial"Returns the top 10 web results with titles, URLs, and descriptions in a clean text format.
搜索网页及相关信息:
bash
python scripts/search.py "<query>"示例:
bash
python scripts/search.py "python asyncio tutorial"返回前10条网页结果,包含标题、URL和描述,格式为简洁的文本。
2. Limiting Results
2. 结果数量限制
Control the number of results returned:
bash
python scripts/search.py "<query>" --max-results <N>Example:
bash
python scripts/search.py "machine learning frameworks" --max-results 20Useful for:
- Getting more comprehensive results (increase limit)
- Quick lookups with fewer results (decrease limit)
- Balancing detail vs. processing time
控制返回的结果数量:
bash
python scripts/search.py "<query>" --max-results <N>示例:
bash
python scripts/search.py "machine learning frameworks" --max-results 20适用场景:
- 获取更全面的结果(提高限制数)
- 快速查询少量结果(降低限制数)
- 平衡结果细节与处理时间
3. Time Range Filtering
3. 时间范围过滤
Filter results by recency:
bash
python scripts/search.py "<query>" --time-range <d|w|m|y>Time range options:
- - Past day
d - - Past week
w - - Past month
m - - Past year
y
Example:
bash
python scripts/search.py "artificial intelligence news" --time-range wGreat for:
- Finding recent news or updates
- Filtering out outdated content
- Tracking recent developments
按时效性过滤结果:
bash
python scripts/search.py "<query>" --time-range <d|w|m|y>时间范围选项:
- - 过去一天
d - - 过去一周
w - - 过去一个月
m - - 过去一年
y
示例:
bash
python scripts/search.py "artificial intelligence news" --time-range w适用场景:
- 查找近期新闻或更新
- 过滤过时内容
- 追踪近期动态
4. News Search
4. 新闻搜索
Search specifically for news articles:
bash
python scripts/search.py "<query>" --type newsExample:
bash
python scripts/search.py "climate change" --type news --time-range w --max-results 15News results include:
- Article title
- Source publication
- Publication date
- URL
- Article summary/description
专门搜索新闻文章:
bash
python scripts/search.py "<query>" --type news示例:
bash
python scripts/search.py "climate change" --type news --time-range w --max-results 15新闻结果包含:
- 文章标题
- 发布来源
- 发布日期
- URL
- 文章摘要/描述
5. Image Search
5. 图片搜索
Search for images:
bash
python scripts/search.py "<query>" --type imagesExample:
bash
python scripts/search.py "sunset over mountains" --type images --max-results 20Image filtering options:
Size filters:
bash
python scripts/search.py "landscape photos" --type images --image-size LargeOptions: , , ,
SmallMediumLargeWallpaperColor filters:
bash
python scripts/search.py "abstract art" --type images --image-color BlueOptions: , , , , , , , , , , , , ,
colorMonochromeRedOrangeYellowGreenBluePurplePinkBrownBlackGrayTealWhiteType filters:
bash
python scripts/search.py "icons" --type images --image-type transparentOptions: , , , ,
photoclipartgiftransparentlineLayout filters:
bash
python scripts/search.py "wallpapers" --type images --image-layout WideOptions: , ,
SquareTallWideImage results include:
- Image title
- Image URL (direct link to image)
- Thumbnail URL
- Source website
- Dimensions (width x height)
搜索图片:
bash
python scripts/search.py "<query>" --type images示例:
bash
python scripts/search.py "sunset over mountains" --type images --max-results 20图片过滤选项:
尺寸过滤:
bash
python scripts/search.py "landscape photos" --type images --image-size Large选项:, , ,
SmallMediumLargeWallpaper颜色过滤:
bash
python scripts/search.py "abstract art" --type images --image-color Blue选项:, , , , , , , , , , , , ,
colorMonochromeRedOrangeYellowGreenBluePurplePinkBrownBlackGrayTealWhite类型过滤:
bash
python scripts/search.py "icons" --type images --image-type transparent选项:, , , ,
photoclipartgiftransparentline布局过滤:
bash
python scripts/search.py "wallpapers" --type images --image-layout Wide选项:, ,
SquareTallWide图片结果包含:
- 图片标题
- 图片URL(直接链接到图片)
- 缩略图URL
- 来源网站
- 尺寸(宽×高)
6. Video Search
6. 视频搜索
Search for videos:
bash
python scripts/search.py "<query>" --type videosExample:
bash
python scripts/search.py "python tutorial" --type videos --max-results 15Video filtering options:
Duration filters:
bash
python scripts/search.py "cooking recipes" --type videos --video-duration shortOptions: , ,
shortmediumlongResolution filters:
bash
python scripts/search.py "documentary" --type videos --video-resolution highOptions: ,
highstandardVideo results include:
- Video title
- Publisher/channel
- Duration
- Publication date
- Video URL
- Description
搜索视频:
bash
python scripts/search.py "<query>" --type videos示例:
bash
python scripts/search.py "python tutorial" --type videos --max-results 15视频过滤选项:
时长过滤:
bash
python scripts/search.py "cooking recipes" --type videos --video-duration short选项:, ,
shortmediumlong分辨率过滤:
bash
python scripts/search.py "documentary" --type videos --video-resolution high选项:,
highstandard视频结果包含:
- 视频标题
- 发布者/频道
- 时长
- 发布日期
- 视频URL
- 描述
7. Region-Specific Search
7. 地区专属搜索
Search with region-specific results:
bash
python scripts/search.py "<query>" --region <region-code>Common region codes:
- - United States (English)
us-en - - United Kingdom (English)
uk-en - - Canada (English)
ca-en - - Australia (English)
au-en - - Germany (German)
de-de - - France (French)
fr-fr - - Worldwide (default)
wt-wt
Example:
bash
python scripts/search.py "local news" --region us-en --type news搜索特定地区的结果:
bash
python scripts/search.py "<query>" --region <region-code>常用地区代码:
- - 美国(英文)
us-en - - 英国(英文)
uk-en - - 加拿大(英文)
ca-en - - 澳大利亚(英文)
au-en - - 德国(德文)
de-de - - 法国(法文)
fr-fr - - 全球(默认)
wt-wt
示例:
bash
python scripts/search.py "local news" --region us-en --type news8. Safe Search Control
8. 安全搜索控制
Control safe search filtering:
bash
python scripts/search.py "<query>" --safe-search <on|moderate|off>Options:
- - Strict filtering
on - - Balanced filtering (default)
moderate - - No filtering
off
Example:
bash
python scripts/search.py "medical information" --safe-search on控制安全搜索过滤级别:
bash
python scripts/search.py "<query>" --safe-search <on|moderate|off>选项:
- - 严格过滤
on - - 平衡过滤(默认)
moderate - - 无过滤
off
示例:
bash
python scripts/search.py "medical information" --safe-search on9. Output Formats
9. 输出格式
Choose how results are formatted:
Text format (default):
bash
python scripts/search.py "quantum computing"Clean, readable plain text with numbered results.
Markdown format:
bash
python scripts/search.py "quantum computing" --format markdownFormatted markdown with headers, bold text, and links.
JSON format:
bash
python scripts/search.py "quantum computing" --format jsonStructured JSON data for programmatic processing.
选择结果的格式:
文本格式(默认):
bash
python scripts/search.py "quantum computing"简洁易读的纯文本,带编号结果。
Markdown格式:
bash
python scripts/search.py "quantum computing" --format markdown带标题、粗体文本和链接的格式化Markdown。
JSON格式:
bash
python scripts/search.py "quantum computing" --format json结构化JSON数据,适用于程序化处理。
10. Saving Results to File
10. 保存结果到文件
Save search results to a file:
bash
python scripts/search.py "<query>" --output <file-path>Example:
bash
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.jsonThe file format is determined by the flag, not the file extension.
--format将搜索结果保存到文件:
bash
python scripts/search.py "<query>" --output <file-path>示例:
bash
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文件格式由参数决定,与文件扩展名无关。
--formatOutput Format Examples
输出格式示例
Text Format
文本格式
1. Page Title Here
URL: https://example.com/page
Brief description of the page content...
2. Another Result
URL: https://example.com/another
Another description...1. 页面标题
URL: https://example.com/page
页面内容的简要描述...
2. 另一结果
URL: https://example.com/another
另一描述...Markdown Format
Markdown格式
markdown
undefinedmarkdown
undefined1. Page Title Here
1. 页面标题
Brief description of the page content...
页面内容的简要描述...
2. Another Result
2. 另一结果
JSON Format
JSON格式
json
[
{
"title": "Page Title Here",
"href": "https://example.com/page",
"body": "Brief description of the page content..."
},
{
"title": "Another Result",
"href": "https://example.com/another",
"body": "Another description..."
}
]json
[
{
"title": "页面标题",
"href": "https://example.com/page",
"body": "页面内容的简要描述..."
},
{
"title": "另一结果",
"href": "https://example.com/another",
"body": "另一描述..."
}
]Common Usage Patterns
常见使用场景
Research on a Topic
主题研究
Gather comprehensive information about a subject:
bash
undefined收集某一主题的全面信息:
bash
undefinedGet overview from web
获取网页概述
python scripts/search.py "machine learning basics" --max-results 15 --output ml_web.txt
python scripts/search.py "machine learning basics" --max-results 15 --output ml_web.txt
Get recent news
获取近期新闻
python scripts/search.py "machine learning" --type news --time-range m --output ml_news.txt
python scripts/search.py "machine learning" --type news --time-range m --output ml_news.txt
Find tutorial videos
查找教程视频
python scripts/search.py "machine learning tutorial" --type videos --max-results 10 --output ml_videos.txt
undefinedpython scripts/search.py "machine learning tutorial" --type videos --max-results 10 --output ml_videos.txt
undefinedCurrent Events Monitoring
时事监控
Track news on specific topics:
bash
python scripts/search.py "climate summit" --type news --time-range d --format markdown --output daily_climate_news.md追踪特定主题的新闻:
bash
python scripts/search.py "climate summit" --type news --time-range d --format markdown --output daily_climate_news.mdFinding Visual Resources
查找视觉资源
Search for images with specific criteria:
bash
python scripts/search.py "data visualization examples" --type images --image-type photo --image-size Large --max-results 25 --output viz_images.txt按特定条件搜索图片:
bash
python scripts/search.py "data visualization examples" --type images --image-type photo --image-size Large --max-results 25 --output viz_images.txtFact-Checking
事实核查
Verify information with recent sources:
bash
python scripts/search.py "specific claim to verify" --time-range w --max-results 20通过近期来源验证信息:
bash
python scripts/search.py "specific claim to verify" --time-range w --max-results 20Academic Research
学术研究
Find resources on scholarly topics:
bash
python scripts/search.py "quantum entanglement research" --time-range y --max-results 30 --output quantum_research.txt查找学术主题的资源:
bash
python scripts/search.py "quantum entanglement research" --time-range y --max-results 30 --output quantum_research.txtMarket Research
市场调研
Gather information about products or companies:
bash
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收集产品或公司相关信息:
bash
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.txtImplementation Approach
实现流程
When users request web searches:
-
Identify search intent:
- What type of content (web, news, images, videos)?
- How recent should results be?
- How many results are needed?
- Any filtering requirements?
-
Configure search parameters:
- Choose appropriate search type ()
--type - Set time range if currency matters ()
--time-range - Adjust result count ()
--max-results - Apply filters (image size, video duration, etc.)
- Choose appropriate search type (
-
Select output format:
- Text for quick reading
- Markdown for documentation
- JSON for further processing
-
Execute search:
- Run the search command
- Save to file if results need to be preserved
- Print to stdout for immediate review
-
Process results:
- Read saved files if needed
- Extract URLs or specific information
- Combine results from multiple searches
当用户请求网页搜索时:
-
识别搜索意图:
- 需要哪种类型的内容(网页、新闻、图片、视频)?
- 结果需要多新?
- 需要多少条结果?
- 有哪些过滤需求?
-
配置搜索参数:
- 选择合适的搜索类型()
--type - 若关注时效性,设置时间范围()
--time-range - 调整结果数量()
--max-results - 应用过滤条件(图片尺寸、视频时长等)
- 选择合适的搜索类型(
-
选择输出格式:
- 快速阅读选文本格式
- 文档编写选Markdown格式
- 后续处理选JSON格式
-
执行搜索:
- 运行搜索命令
- 若需保存结果,使用输出文件参数
- 直接打印到标准输出以便即时查看
-
处理结果:
- 若有需要,读取保存的文件
- 提取URL或特定信息
- 合并多次搜索的结果
Quick Reference
快速参考
Command structure:
bash
python scripts/search.py "<query>" [options]Essential options:
- - Search type (web, news, images, videos)
-t, --type - - Maximum results (default: 10)
-n, --max-results - - Time filter (d, w, m, y)
--time-range - - Region code (e.g., us-en, uk-en)
-r, --region - - Safe search level (on, moderate, off)
--safe-search - - Output format (text, markdown, json)
-f, --format - - Save to file
-o, --output
Image-specific options:
- - Size filter (Small, Medium, Large, Wallpaper)
--image-size - - Color filter
--image-color - - Type filter (photo, clipart, gif, transparent, line)
--image-type - - Layout filter (Square, Tall, Wide)
--image-layout
Video-specific options:
- - Duration filter (short, medium, long)
--video-duration - - Resolution filter (high, standard)
--video-resolution
Get full help:
bash
python scripts/search.py --help命令结构:
bash
python scripts/search.py "<query>" [options]核心选项:
- - 搜索类型(web, news, images, videos)
-t, --type - - 最大结果数(默认:10)
-n, --max-results - - 时间过滤(d, w, m, y)
--time-range - - 地区代码(如us-en, uk-en)
-r, --region - - 安全搜索级别(on, moderate, off)
--safe-search - - 输出格式(text, markdown, json)
-f, --format - - 保存到文件
-o, --output
图片专属选项:
- - 尺寸过滤(Small, Medium, Large, Wallpaper)
--image-size - - 颜色过滤
--image-color - - 类型过滤(photo, clipart, gif, transparent, line)
--image-type - - 布局过滤(Square, Tall, Wide)
--image-layout
视频专属选项:
- - 时长过滤(short, medium, long)
--video-duration - - 分辨率过滤(high, standard)
--video-resolution
获取完整帮助:
bash
python scripts/search.py --helpBest Practices
最佳实践
- Be specific - Use clear, specific search queries for better results
- Use time filters - Apply for current information
--time-range - Adjust result count - Start with 10-20 results, increase if needed
- Save important searches - Use to preserve results
--output - Choose appropriate type - Use news search for current events, web for general info
- Use JSON for automation - JSON format is easiest to parse programmatically
- Respect usage - Don't hammer the API with rapid repeated searches
- 查询具体 - 使用清晰、具体的搜索词以获得更优结果
- 使用时间过滤 - 若需最新信息,应用参数
--time-range - 调整结果数量 - 先获取10-20条结果,必要时再增加
- 保存重要搜索 - 使用参数保存结果
--output - 选择合适类型 - 时事用新闻搜索,通用信息用网页搜索
- 自动化用JSON - JSON格式最便于程序化解析
- 合理使用 - 避免频繁连续调用API
Troubleshooting
故障排除
Common issues:
- "Missing required dependency": Run
pip install duckduckgo-search - No results found: Try broader search terms or remove time filters
- Timeout errors: The search service may be temporarily unavailable; retry after a moment
- Rate limiting: Space out searches if making many requests
- Unexpected results: DuckDuckGo's results may differ from Google; try refining the query
Limitations:
- Results quality depends on DuckDuckGo's index and algorithms
- No advanced search operators (unlike Google's site:, filetype:, etc.)
- Image and video searches may have fewer results than web search
- No control over result ranking or relevance scoring
- Some specialized searches may work better on dedicated search engines
常见问题:
- "Missing required dependency":运行
pip install duckduckgo-search - 无结果返回:尝试更宽泛的搜索词或移除时间过滤
- 超时错误:搜索服务可能暂时不可用,稍后重试
- 速率限制:若进行大量请求,需间隔搜索时间
- 结果不符合预期:DuckDuckGo的结果可能与Google不同,尝试优化查询词
局限性:
- 结果质量取决于DuckDuckGo的索引和算法
- 不支持高级搜索运算符(如Google的site:, filetype:等)
- 图片和视频搜索的结果数量可能少于网页搜索
- 无法控制结果排序或相关性评分
- 某些专业搜索在专用搜索引擎上效果更好
Advanced Use Cases
高级使用场景
Combining Multiple Searches
合并多次搜索
Gather comprehensive information by combining search types:
bash
undefined通过合并不同类型的搜索收集全面信息:
bash
undefinedWeb overview
网页概述
python scripts/search.py "topic" --max-results 15 --output topic_web.txt
python scripts/search.py "topic" --max-results 15 --output topic_web.txt
Recent news
近期新闻
python scripts/search.py "topic" --type news --time-range w --output topic_news.txt
python scripts/search.py "topic" --type news --time-range w --output topic_news.txt
Images
图片
python scripts/search.py "topic" --type images --max-results 20 --output topic_images.txt
undefinedpython scripts/search.py "topic" --type images --max-results 20 --output topic_images.txt
undefinedProgrammatic Processing
程序化处理
Use JSON output for automated processing:
bash
python scripts/search.py "research topic" --format json --output results.json使用JSON输出进行自动化处理:
bash
python scripts/search.py "research topic" --format json --output results.jsonThen process with another script
随后用其他脚本处理
python analyze_results.py results.json
undefinedpython analyze_results.py results.json
undefinedBuilding a Knowledge Base
构建知识库
Create searchable documentation from web results:
bash
undefined从网页结果创建可搜索的文档:
bash
undefinedSearch multiple related topics
搜索多个相关主题
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
undefinedpython 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
undefinedResources
资源
scripts/search.py
scripts/search.py
The main search tool implementing DuckDuckGo search functionality. Key features:
- Multiple search types - Web, news, images, and videos
- Flexible filtering - Time range, region, safe search, and type-specific filters
- Multiple output formats - Text, Markdown, and JSON
- File output - Save results for later processing
- Clean formatting - Human-readable output with all essential information
- Error handling - Graceful handling of network errors and empty results
The script can be executed directly and includes comprehensive command-line help via .
--help实现DuckDuckGo搜索功能的核心工具。主要特性:
- 多种搜索类型 - 网页、新闻、图片和视频
- 灵活过滤 - 时间范围、地区、安全搜索及专属类型过滤
- 多种输出格式 - 文本、Markdown和JSON
- 文件输出 - 保存结果供后续处理
- 简洁格式化 - 包含所有关键信息的易读输出
- 错误处理 - 优雅处理网络错误和空结果
该脚本可直接执行,通过参数可查看完整的命令行帮助。
--help