基于 go-rod 的视频资源嗅探器 Golang 实现。
- 🎯 媒体嗅探: 自动检测和提取网页中的视频/音频资源 URL
- 🌐 多模式支持: 支持单个 URL 嗅探和批量 URL 收集
- 📱 设备模拟: 支持 PC 和移动设备模拟
- 🔧 自定义脚本: 支持页面初始化脚本和执行脚本
- 📄 页面源码: 获取动态渲染后的页面 HTML 源码
- ⚡ 高性能: 基于 Chrome DevTools Protocol,性能优异
- 🛡️ 反检测: 内置反自动化检测机制
- Go >= 1.21
- Chrome 浏览器 (用于 go-rod)
- 支持 Windows、Linux、macOS
cd golang
go mod tidy# 使用默认端口 (自动查找可用端口,从 57573 开始)
go run .
# 指定端口
go run . -port 8080
# 查看帮助
go run . -help# 编译当前平台
go build -o pup-sniffer .
# 交叉编译 Windows
GOOS=windows GOARCH=amd64 go build -o pup-sniffer.exe .
# 交叉编译 Linux
GOOS=linux GOARCH=amd64 go build -o pup-sniffer-linux .GET /sniffer
参数:
url(必需): 目标页面 URLmode(可选): 嗅探模式0: 单个 URL 模式 (找到第一个匹配的 URL 后立即返回)1: 批量 URL 模式 (收集所有匹配的 URL)
is_pc(可选): 设备模式0: 移动设备模拟 (默认)1: PC 设备模拟
timeout(可选): 超时时间,单位毫秒 (默认: 10000,最大: 60000)custom_regex(可选): 自定义正则表达式sniffer_exclude(可选): 排除正则表达式css(可选): CSS 选择器,等待元素出现script(可选): 页面脚本 (Base64 编码)init_script(可选): 初始化脚本 (Base64 编码)headers(可选): 自定义请求头,格式为 "key: value" 每行一个
示例:
curl "http://localhost:57573/sniffer?url=https://example.com&mode=0&timeout=10000"GET /fetCodeByWebView
获取动态渲染后的页面 HTML 源码。
参数: 与嗅探接口相同 (除了 mode, custom_regex, sniffer_exclude)
示例:
curl "http://localhost:57573/fetCodeByWebView?url=https://example.com&timeout=10000"GET /health
检查服务状态。
GET /active
检查服务和浏览器状态。
所有接口都返回统一的 JSON 格式:
{
"code": 200,
"msg": "success",
"data": {
// 具体数据
},
"timestamp": 1640995200000
}{
"code": 200,
"msg": "success",
"data": {
"url": "https://example.com/video.m3u8",
"headers": {
"referer": "https://example.com",
"user-agent": "Mozilla/5.0..."
},
"from": "https://example.com",
"cost": "2500 ms",
"total_cost": "2600 ms",
"code": 200,
"msg": "超级嗅探解析成功"
}
}{
"code": 200,
"msg": "success",
"data": {
"urls": [
{
"url": "https://example.com/video1.m3u8",
"headers": {
"referer": "https://example.com"
}
},
{
"url": "https://example.com/video2.mp4",
"headers": {
"referer": "https://example.com"
}
}
],
"from": "https://example.com",
"cost": "5000 ms",
"total_cost": "5100 ms",
"code": 200,
"msg": "超级嗅探解析成功"
}
}config := &SnifferConfig{
Debug: true, // 启用调试日志
Headless: true, // 无头模式
UseChrome: true, // 使用系统 Chrome
DeviceType: "mobile", // 默认移动设备
Timeout: 30000, // 默认超时 30 秒
SnifferTimeout: 10000, // 嗅探超时 10 秒
HeadTimeout: 5000, // HEAD 请求超时 5 秒
ConcurrencyNum: 3, // 并发数
}HOST: 服务器监听地址 (默认: 0.0.0.0)
- 性能: Golang 版本在并发处理和内存使用方面更优
- 部署: 编译后的二进制文件更容易部署,无需 Node.js 环境
- 依赖: 使用 go-rod 替代 puppeteer,功能基本一致
- API: 保持与原版 100% 兼容的 API 接口
确保系统已安装 Chrome 浏览器,或者设置 UseChrome: false 使用内置浏览器。
使用 -port 参数指定其他端口,或让程序自动查找可用端口。
根据目标网站的加载速度调整 timeout 参数。
- 检查目标 URL 是否可访问
- 尝试使用自定义正则表达式
- 检查是否需要特殊的请求头或脚本
golang/
├── go.mod # Go 模块文件
├── sniffer.go # 嗅探器核心实现
├── server.go # HTTP 服务器实现
└── README.md # 说明文档
- Sniffer: 嗅探器核心,基于 go-rod 实现
- Server: HTTP 服务器,基于 Gin 框架
- APIResponse: 统一的响应格式
与主项目保持一致的许可证。