介绍
# SearXNG Search
尊重隐私的元搜索引擎,可匿名搜索并聚合 250 多个搜索引擎的结果。
## 快速开始
使用捆绑脚本搜索网络:
```bash python3 scripts/search.py "your query" ```
返回包含标题、URL 和内容片段的 JSON。
## 常见工作流
### 基本网络搜索
```bash python3 scripts/search.py "OpenClaw AI agent" --num 5 ```
### 新闻搜索
```bash python3 scripts/search.py "latest tech news" --categories news ```
### 本地化搜索
```bash python3 scripts/search.py "Python Tutorial" --lang de ```
### 多类别搜索
```bash python3 scripts/search.py "machine learning" --categories general,science --num 10 ```
### Bang 搜索(直达引擎)
```bash # Wikipedia python3 scripts/search.py "Albert Einstein" --bang w
# YouTube python3 scripts/search.py "python tutorial" --bang yt
# GitHub python3 scripts/search.py "openclaw" --bang gh
# Reddit python3 scripts/search.py "best laptop 2026" --bang r ```
Bang 比类别更细粒度,并直接在特定引擎上搜索。
## 隐私功能
SearXNG 通过多层机制保护您的隐私:
1. **随机化浏览器指纹** - 为每次搜索查询生成一个新的虚假浏览器配置文件(版本、操作系统、屏幕分辨率、语言) 2. **IP 掩码** - 搜索引擎看到的是 SearXNG 实例的 IP,而不是您的 IP 3. **无 Cookie** - 永不将 Cookie 转发到外部搜索引擎 4. **无 Referer** - 目标网站看不到是哪个搜索引擎将您引导至此 5. **可选 Tor/代理** - 可以通过 Tor 路由所有查询以增加匿名性
**结果:** 搜索引擎无法建立关于您的画像。
## 何时使用
**优先使用 SearXNG 的场景:** - 隐私敏感的搜索(无跟踪、无画像) - 高频搜索(无速率限制) - 当有自托管基础设施可用时 - 多引擎结果聚合(250 多个引擎) - 无广告结果
**优先使用 Brave API(`web_search` 工具)的场景:** - 更快的响应时间 - 结构化数据要求 - 当外部 API 可接受时
## 处理结果
该脚本返回易于解析和展示的干净 JSON:
```python import json import subprocess
result = subprocess.run( ['python3', 'scripts/search.py', 'query', '--num', '5'], capture_output=True, text=True )
data = json.loads(result.stdout) for item in data['results']: print(f"Title: {item['title']}") print(f"URL: {item['url']}") print(f"Snippet: {item['content']}") print() ```
## 高级选项
参见 `references/api.md` 了解: - 所有可用类别 - 特定引擎搜索 - 语言代码 - 错误处理 - 与 Brave Search API 的比较
## 配置
### SearXNG 实例
默认情况下,脚本使用 `http://127.0.0.1:8080`。通过环境变量进行配置:
```bash export SEARXNG_URL=http://your-searxng-instance.com python3 scripts/search.py "query" ```
**选项:** - 自托管实例(推荐用于隐私保护) - 公共实例:https://searx.space(社区运行的服务器)
### 使用公共实例
如果您不运行自己的 SearXNG:
```bash # Example with public instance export SEARXNG_URL=https://searx.be python3 scripts/search.py "query" ```
**注意:** 公共实例可能具有速率限制,或者比自托管实例更慢。
## 技术细节
- **默认 URL:** `http://127.0.0.1:8080`(可通过 `SEARXNG_URL` 覆盖) - **方法:** HTML 解析(出于 CSRF 保护,JSON API 通常被禁用) - **解析器:** `scripts/search.py` 中的自定义 HTMLParser - **超时时间:** 15 秒 - **结果格式:** 包含 title、URL、content 的干净 JSON