DedSecInside/gotor
GitHub: DedSecInside/gotor
GoTor 是一个支持 Tor SOCKS5 代理的并发 Web 爬虫,提供 CLI 和 REST API 两种使用方式,适用于普通网站和 Tor 隐藏服务的数据采集。
Stars: 170 | Forks: 45
# GoTor
GoTor 是一个具备一流 Tor SOCKS5 支持的并发 Web 爬虫。它可以
作为人性化的 CLI 运行,输出带有版本控制的 JSON 爬取报告,或为
TorBot App 等应用程序提供本地作业控制 HTTP API。
## 环境要求
- Go 1.24 或更新版本
- 默认在 `127.0.0.1:9050` 上的 Tor SOCKS5 代理(可选)
## 快速开始
```
go build -o bin/gotor ./cmd/main
# 通过 Tor 进行爬取
./bin/gotor -url https://example.com -depth 1
# 直接进行爬取并输出 integration-safe 的 JSON schema
./bin/gotor \
-url https://example.com \
-depth 1 \
-disable-socks5 \
-f json
```
深度是包含在内的:根深度为 `0`,因此 `-depth 1` 会抓取根页面及其
直接链接。
## HTTP API
启动服务:
```
./bin/gotor -s -server-host 127.0.0.1 -server-port 8081
```
启动并检查爬取作业:
```
curl -sS \
-H 'content-type: application/json' \
-d '{
"url": "https://example.com",
"depth": 1,
"useTor": false,
"randomizeHeaders": true
}' \
http://127.0.0.1:8081/api/v1/jobs
curl -sS http://127.0.0.1:8081/api/v1/jobs/JOB_ID
curl -sS -X POST http://127.0.0.1:8081/api/v1/jobs/JOB_ID/cancel
```
健康和就绪探针位于 `/_healthz` 和 `/_readyz`。
Tor 配置和代理就绪状态位于:
```
curl -sS 'http://127.0.0.1:8081/api/v1/tor/status?host=127.0.0.1&port=9050'
```
诊断报告会显示选定的 SOCKS endpoint 是否可达、检测到的 `torrc`
路径、已配置的 SOCKS 和控制端口、Tor 数据目录以及 Tor 可执行文件。当 Tor 使用非标准配置位置时,请设置 `TORRC_PATH`。
有关完整的请求和响应契约,请参见 [docs/API.md](docs/API.md)。
## 爬取控制
```
-url URL Root URL to crawl
-depth N Maximum depth, 0-10 (default 1)
-workers N Global worker count (default 16)
-queue N Frontier capacity (default 2048)
-rps N Global requests per second (default 5)
-burst N Global limiter burst (default 5)
-per-host-parallel N Concurrent requests to one host (default 2)
-per-host-delay MS Delay between requests to one host
-max-response-bytes N Largest response parsed in memory (default 5 MiB)
-randomize-headers Rotate browser user-agent headers
-allow-non-html Attempt to parse non-HTML responses
-socks5-host HOST Tor SOCKS5 host (default 127.0.0.1)
-socks5-port PORT Tor SOCKS5 port (default 9050)
-disable-socks5 Use a direct connection
-f list|tree|json CLI output format
-log-format text|json Structured log format
-log-level LEVEL debug, info, warn, or error
```
GoTor 默认会跳过过大和非 HTML 的 body,但会将这些页面以及
跳过原因记录在报告中。单个页面的失败也会被返回,而不会
丢弃成功的结果。
## 容器
该镜像是一个多阶段、非 root 的 distroless 构建:
```
docker build -t gotor .
docker run --rm -p 8081:8081 gotor
```
如果容器需要 Tor 代理,请将其连接到相关网络,并在
覆盖镜像命令时传入 `-socks5-host`。
## 开发
```
go fmt ./...
go vet ./...
go test -race ./...
```
GoTor 采用 GNU General Public License 进行授权。请参阅 [LICENSE](LICENSE)。
标签:EVTX分析, Go, RESTful API, Ruby工具, SOCKS5, Tor, 提示词优化, 日志审计, 请求拦截