idkwhodatis-ddgs
基于 DDGS 元搜索引擎的网页/新闻/图片/视频/图书搜索,隐私友好、无需 API Key,支持 MCP。
安装 / 下载方式
TotalClaw CLI推荐
totalclaw skills install shop:totalclaw:totalclaw~idkwhodatis-ddgscURL直接下载,无需登录
curl -fsSL https://skills.taituai.com/api/skills/totalclaw%3Atotalclaw~idkwhodatis-ddgs/file -o idkwhodatis-ddgs.md## 概述(中文)
基于 DDGS 元搜索引擎的网页/新闻/图片/视频/图书搜索,隐私友好、无需 API Key,支持 MCP。
## 技能正文
# DDGS 网页搜索技能
本技能通过 DDGS(Dux Distributed Global Search)引擎实现网页搜索,聚合多种搜索服务以获取实时信息。
## 功能
🔍 隐私友好的元搜索
📰 新闻搜索
🖼️ 图片搜索
📹 视频搜索
📚 图书搜索
🌐 免费使用,无需 API Key
🔒 隐私保护,无用户追踪
⚡ 支持 MCP(Model Context Protocol)与 API 服务器
## 安装
```bash
# 通过 uv 安装(推荐)
uv pip install ddgs
# 或通过 pip 安装
pip install ddgs
```
## 快速开始
### 1. 文本搜索
最常用的搜索方式,返回网页结果:
```python
python -c "
from ddgs import DDGS
query = 'your search query'
results = DDGS().text(
query,
region='wt-wt', # 区域:cn-zh(中国)、us-en(美国)、wt-wt(全球)
safesearch='moderate', # 安全搜索:on、moderate、off
timelimit='m', # 时间范围:d(天)、w(周)、m(月)、y(年)、None(不限)
max_results=10, # 最大结果数
backend='auto' # 后端:auto、duckduckgo、brave、bing 等
)
for i, r in enumerate(results, 1):
print(f\"{i}. {r.get('title')}\")
print(f\" URL: {r.get('href')}\")
print(f\" Snippet: {str(r.get('body'))[:100]}...\n\")
"
```
### 2. 新闻搜索
搜索最新新闻:
```python
python -c "
from ddgs import DDGS
results = DDGS().news(
'AI technology',
region='wt-wt',
safesearch='moderate',
timelimit='d', # d=过去24小时,w=过去一周,m=过去一月
max_results=10
)
for r in results:
print(f\"📰 {r.get('title')}\")
print(f\" Source: {r.get('source')}\")
print(f\" Date: {r.get('date')}\")
print(f\" Link: {r.get('url')}\n\")
"
```
### 3. 图片搜索
```python
python -c "
from ddgs import DDGS
results = DDGS().images(
'cute cats',
region='wt-wt',
safesearch='moderate',
size='Medium', # Small、Medium、Large、Wallpaper
type_image='photo', # photo、clipart、gif、transparent、line
layout='Square', # Square、Tall、Wide
max_results=10
)
for r in results:
print(f\"🖼️ {r.get('title')}\")
print(f\" Image: {r.get('image')}\")
print(f\" Thumbnail: {r.get('thumbnail')}\")
print(f\" Source: {r.get('source')}\n\")
"
```
### 4. 视频搜索
```python
python -c "
from ddgs import DDGS
results = DDGS().videos(
'Python programming',
region='wt-wt',
safesearch='moderate',
timelimit='w', # d、w、m
resolution='high', # high、standard
duration='medium', # short、medium、long
max_results=10
)
for r in results:
print(f\"📹 {r.get('title')}\")
print(f\" Duration: {r.get('duration', 'N/A')}\")
print(f\" Publisher: {r.get('publisher')}\")
print(f\" Link: {r.get('content')}\n\")
"
```
### 5. 图书搜索
```python
python -c "
from ddgs import DDGS
results = DDGS().books(
'sea wolf jack london',
max_results=5
)
for r in results:
print(f\"📚 {r.get('title')}\")
print(f\" Author: {r.get('author')}\")
print(f\" Publisher: {r.get('publisher')}\")
print(f\" Link: {r.get('link')}\n\")
"
```
## 实用脚本
### 可复用搜索函数
```python
python -c "
from ddgs import DDGS
def web_search(query, search_type='text', max_results=5, region='wt-wt', timelimit=None):
'''
执行 DDGS 搜索
Args:
query: 搜索关键词
search_type: text、news、images、videos、books
max_results: 最大结果数
region: 区域(cn-zh、us-en、wt-wt)
timelimit: 时间限制(d、w、m、y)
'''
ddgs = DDGS()
if search_type == 'text':
return list(ddgs.text(query, region=region, timelimit=timelimit, max_results=max_results))
elif search_type == 'news':
return list(ddgs.news(query, region=region, timelimit=timelimit, max_results=max_results))
elif search_type == 'images':
return list(ddgs.images(query, region=region, max_results=max_results))
elif search_type == 'videos':
return list(ddgs.videos(query, region=region, timelimit=timelimit, max_results=max_results))
elif search_type == 'books':
return list(ddgs.books(query, max_results=max_results))
return []
results = web_search('Python 3.12 new features', max_results=5)
print(f'📊 Found {len(results)} results')
"
```
## 参数说明
### 区域代码(region)
| 代码 | 区域 |
|---|---|
| cn-zh | 中国 |
| us-en | 美国 |
| uk-en | 英国 |
| jp-jp | 日本 |
| kr-kr | 韩国 |
| wt-wt | 全球(无区域限制) |
### 时间限制(timelimit)
| 值 | 含义 |
|---|---|
| d | 过去 24 小时 |
| w | 过去一周 |
| m | 过去一月 |
| y | 过去一年 |
| None | 无限制 |
### 安全搜索(safesearch)
| 值 | 含义 |
|---|---|
| on | 严格过滤 |
| moderate | 中等过滤(默认) |
| off | 关闭过滤 |
## 错误处理与代理
### 基本错误处理
```python
python -c "
from ddgs import DDGS
from ddgs.exceptions import DDGSException
try:
results = DDGS().text('test query', max_results=5)
print(f'✅ Search successful, found {len(results)} results')
except DDGSException as e:
print(f'❌ Search error: {e}')
except Exception as e:
print(f'❌ Unknown error: {e}')
"
```
### 使用代理
```python
python -c "
from ddgs import DDGS
# 设置代理(支持 http/https/socks5)
proxy = 'http://127.0.0.1:7890'
results = DDGS(proxy=proxy).text('test query', max_results=5)
print(f'Successfully searched via proxy, found {len(results)} results')
"
```
## 常见问题
**安装失败?**
```bash
pip install --upgrade pip
pip install ddgs
```
**没有结果?**
- 检查网络连接
- 尝试使用代理
- 简化搜索查询
- 验证区域设置是否正确
**被限流?**
- 多次请求之间添加延迟(例如 `import time; time.sleep(1)`)
- 减少每次请求的 `max_results`
## 集成与注意事项
### 集成示例
```python
# 1. 用 DDGS 搜索
python -c "
from ddgs import DDGS
results = DDGS().text('Python async tutorial', max_results=1)
if results:
print(f\"URL: {results[0].get('href')}\")
"
# 2. 用 browser-use 工具打开结果
browser-use open <url_from_search>
```
**⚠️ 最佳实践:**
- **尊重速率限制**:避免短时间内发送大量请求
- **优化结果**:单次查询不要请求过多结果
- **添加延迟**:批量搜索时使用 `time.sleep()`
- **处理异常**:始终用 `try/except` 包裹 API 调用
- **版权意识**:搜索结果仅供参考,请尊重被索引内容的版权