使用说明
MCP Camoufox 抓取服务器
一个概念验证的MCP(模型上下文协议)服务器,它使用Camoufox在禁用JavaScript的情况下进行网页抓取,并监控网络请求。
🚀 快速入门
先决条件
- Python 3.10 或更高版本
- 诗歌(Python依赖管理器)
- macOS、Linux 或 Windows
1. 克隆/下载项目
git clone <your-repo> mcp-camoufox-scraper
cd mcp-camoufox-scraper
2. 安装 Poetry(如果尚未安装)
curl -sSL https://install.python-poetry.org | python3 -
3. 安装依赖项
poetry install
4. 验证设置
poetry run python setup_verify.py
你应该看到所有的检查都通过了:
🎉 Setup verification successful!
5. 运行完整测试
poetry run python test_mcp_server.py
你应该看到:
🎉 MCP Server POC is ready!
The server can now be used with MCP clients to scrape websites with JS disabled.
🔌 正在连接到MCP客户端
Claude 桌面集成
-
找到你的Claude桌面配置文件:
- macOS(苹果电脑操作系统):
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux(发音为“林克斯”):
~/.config/Claude/claude_desktop_config.json
- macOS(苹果电脑操作系统):
-
添加服务器配置:
{
"mcpServers": {
"camoufox-scraper": {
"command": "poetry",
"args": ["run", "python", "/full/path/to/your/mcp-camoufox-scraper/run_server.py"],
"cwd": "/full/path/to/your/mcp-camoufox-scraper"
}
}
}
- 替换路径 根据您实际的项目目录:
# Get your full path
pwd
# Copy the output and use it in the config above
-
重启Claude桌面版 完全(退出并重新打开)
-
验证连接 通过询问克劳德:
“你能访问哪些MCP服务器?”
你应该在可用工具列表中看到“camoufox-scraper”。
其他MCP客户端
对于其他MCP客户端,请使用以下服务器配置:
- 命令:
poetry - 论点;争论点:
["run", "python", "/path/to/run_server.py"] - 工作目录:
/path/to/mcp-camoufox-scraper - 沟通stdio(标准输入输出库)
🛠️ 功能
- 双JavaScript模式已启用JavaScript以进行网络监控,禁用以进行干净的HTML提取
- 网络请求监控捕获页面加载期间所有发起的XHR/API调用和HTTP请求
- 干净的HTML提取获取禁用JavaScript时的HTML内容,以避免动态修改
- MCP协议集成与任何MCP客户端(如Claude Desktop等)兼容
📋 可用工具
1. navigate_to_url
导航至一个启用JavaScript的URL,以捕获网络请求和动态内容。
参数:
url(必填):要导航到的URLwait_time(可选):页面加载后等待的时间(以秒为单位)(默认:3)
克劳德 示例:
“请导航至 https://example.com 并等待5秒”
2. get_page_html
通过禁用JavaScript重新加载页面,提取干净的HTML内容。
参数: 无
克劳德 示例:
“从当前页面获取HTML内容”
3. get_network_requests
获取上一次页面导航中捕获的所有网络请求。
参数:
filter_type(可选):按请求类型过滤(“xhr”,“fetch”,“all”)- 默认: “all”
克劳德·埃克萨姆普尔(注:此处为音译,实际翻译可能因人名具体发音和背景而异,Claude为常见的西方人名,Example可能为姓氏或特定名称的一部分):
“显示所有捕获的网络请求”
4. close_browser
关闭浏览器并清理资源。
参数: 无
克劳德·埃克萨姆普尔(Claude Example,此处为假设人名,实际翻译可能因具体人名而异):
“关闭浏览器以释放资源”
💡 使用示例
基础网页抓取
You: Navigate to https://news.ycombinator.com
Claude: [Uses navigate_to_url tool]
You: Get the HTML content
Claude: [Uses get_page_html tool and analyzes the content]
You: What network requests were made?
Claude: [Uses get_network_requests tool and shows API calls]
API发现
You: Go to https://httpbin.org/headers and show me what requests it makes
Claude: [Navigates and shows network monitoring results]
内容分析
You: Navigate to https://example.com and get both the network requests and clean HTML
Claude: [Navigates with JS enabled to capture requests, then extracts HTML with JS disabled]
You: What's the difference between the two modes?
Claude: [Explains that navigation captures dynamic requests while HTML extraction gives clean content]
🧪 测试与验证
运行完整测试套件
poetry run python test_mcp_server.py
预期输出:
=== Testing MCP Server Tools ===
✓ Navigation successful: Example Domain
✓ HTML extraction successful
✓ Network requests retrieval successful
✓ Complex site navigation successful
✓ Browser closed successfully
🎉 MCP Server POC is ready!
测试单个组件
# Test just the Camoufox API
poetry run python test_camoufox_api.py
# Start server manually (for debugging)
poetry run python run_server.py
🔧 故障排除
快速诊断
# Run the setup verification script first
poetry run python setup_verify.py
这将检查您的Python版本、依赖项、项目结构,并生成正确的Claude Desktop配置。
服务器无法启动
# Check if dependencies are installed
poetry show mcp camoufox
# Run the test to identify issues
poetry run python test_mcp_server.py
Claude 桌面连接问题
- 检查配置文件位置 - 确保你正在编辑的是正确的文件
- 使用绝对路径 - 相对路径不起作用
- 重启Claude桌面版 配置更改后完全(生效/完成)
- 检查Claude的开发者工具 用于错误消息
- 验证Python路径 - 确保
python命令在终端中有效
浏览器问题
- Camoufox 下载首次运行时可能需要一些时间来下载浏览器二进制文件
- 权限错误确保脚本具有执行权限(
chmod +x run_server.py) - 端口冲突如果正在运行,请关闭其他浏览器自动化工具
常见错误信息
"No such file or directory"→ 检查你的配置中的路径"Permission denied"→ 运行chmod +x run_server.py"Module not found"→ 跑poetry install
📁 项目结构
mcp-camoufox-scraper/
├── mcp_camoufox_scraper/
│ ├── __init__.py
│ └── server.py # Main MCP server implementation
├── run_server.py # CLI runner script
├── setup_verify.py # Setup verification & config generator
├── test_mcp_server.py # Comprehensive test suite
├── test_camoufox_api.py # Camoufox API validation
├── pyproject.toml # Project configuration & dependencies
├── poetry.lock # Locked dependency versions
└── README.md # This file
⚠️ 局限性
- 双语境方法HTML提取需要在禁用JS的情况下重新导航
- 单页一次只能有一个页面处于激活状态
- 未进行身份验证目前不支持登录/认证工作流程
- 仅限于HTTP/HTTPS不支持其他协议
🔒 安全与隐私
- 不收集数据服务器在本地运行,不向外部服务发送数据
- 控制JavaScript的执行仅在网络监控需要时启用JavaScript
- 注重隐私的浏览器Camoufox旨在保护隐私
- 本地执行所有的抓取操作都在您的机器上进行
🛠️ 开发与扩展
修改服务器
- 编辑
mcp_camoufox_scraper/server.py - 测试更改:
poetry run python test_mcp_server.py - 与您的客户验证MCP(微软认证合作伙伴)合规性
添加新工具
# In server.py, add to _register_tools():
@self.server.call_tool()
async def handle_call_tool(name: str, arguments: Dict[str, Any]):
if name == "your_new_tool":
return await self._your_new_tool(arguments)
技术细节
- 浏览器Camoufox(基于Firefox,注重隐私保护)
- 协议MCP(模型上下文协议)
- 语言Python 3.10+ 并带有 asyncio 支持
- 依赖项MCP SDK,Camoufox 浏览器自动化
📝 许可证
MIT 许可证 - 欢迎自由使用、修改和分发。
🤝 贡献
这是一个概念验证项目。请随意:
- 针对您的使用场景进行分支和扩展
- 提交问题和改进建议
- 与社区分享您的修改
祝你刮刮乐愉快!(注:这里的“scraping”在中文里可能不直接对应“刮刮乐”这种游戏,但根据语境,可以理解为类似刮奖、刮刮卡等带有随机奖励性质的活动,因此采用“刮刮乐”作为意译,以贴近原文的轻松愉快氛围。)! 蜘蛛🕷️