WebScraping.AI MCP Server
一个模型上下文协议 (MCP) 服务器实现,集成了 WebScraping.AI 以提供网页数据提取功能。
webscraping-ai
README
WebScraping.AI MCP 服务器
一个模型上下文协议 (MCP) 服务器的实现,它与 WebScraping.AI 集成,提供网页数据提取功能。
功能特性
- 关于网页内容的问答
- 从网页中提取结构化数据
- 获取带有 JavaScript 渲染的 HTML 内容
- 从网页中提取纯文本
- 基于 CSS 选择器的内容提取
- 多种代理类型(数据中心、住宅),并支持国家选择
- 使用无头 Chrome/Chromium 进行 JavaScript 渲染
- 并发请求管理与速率限制
- 在目标页面上执行自定义 JavaScript
- 设备模拟(桌面、移动设备、平板电脑)
- 账户使用情况监控
安装
使用 npx 运行
env WEBSCRAPING_AI_API_KEY=your_api_key npx -y webscraping-ai-mcp
手动安装
# 克隆仓库
git clone https://github.com/webscraping-ai/webscraping-ai-mcp-server.git
cd webscraping-ai-mcp-server
# 安装依赖
npm install
# 运行
npm start
在 Cursor 上运行
配置 Cursor 🖥️ 注意:需要 Cursor 版本 0.45.6+
要在 Cursor 中配置 WebScraping.AI MCP:
- 打开 Cursor 设置
- 转到 Features > MCP Servers
- 点击 "+ Add New MCP Server"
- 输入以下内容:
- Name: "webscraping-ai-mcp" (或您喜欢的名称)
- Type: "command"
- Command:
env WEBSCRAPING_AI_API_KEY=your-api-key npx -y webscraping-ai-mcp
如果您正在使用 Windows 并且遇到问题,请尝试
cmd /c "set WEBSCRAPING_AI_API_KEY=your-api-key && npx -y webscraping-ai-mcp"
将 your-api-key
替换为您的 WebScraping.AI API 密钥。
在 Claude Desktop 上运行
将此添加到您的 claude_desktop_config.json
:
{
"mcpServers": {
"mcp-server-webscraping-ai": {
"command": "npx",
"args": ["-y", "webscraping-ai-mcp"],
"env": {
"WEBSCRAPING_AI_API_KEY": "YOUR_API_KEY_HERE",
"WEBSCRAPING_AI_CONCURRENCY_LIMIT": "5"
}
}
}
}
配置
环境变量
必需
WEBSCRAPING_AI_API_KEY
: 您的 WebScraping.AI API 密钥- 所有操作都需要
- 从 WebScraping.AI 获取您的 API 密钥
并发配置
WEBSCRAPING_AI_CONCURRENCY_LIMIT
: 最大并发请求数(默认值:5
)
配置示例
对于具有自定义并发设置的标准用法:
# 必需
export WEBSCRAPING_AI_API_KEY=your-api-key
# 可选
export WEBSCRAPING_AI_CONCURRENCY_LIMIT=10 # 增加并发限制
可用工具
1. 问题工具 (webscraping_ai_question
)
询问关于网页内容的问题。
{
"name": "webscraping_ai_question",
"arguments": {
"url": "https://example.com",
"question": "What is the main topic of this page?",
"timeout": 30000,
"js": true,
"js_timeout": 2000,
"wait_for": ".content-loaded",
"proxy": "datacenter",
"country": "us"
}
}
示例响应:
{
"content": [
{
"type": "text",
"text": "The main topic of this page is examples and documentation for HTML and web standards."
}
],
"isError": false
}
2. 字段工具 (webscraping_ai_fields
)
根据指令从网页中提取结构化数据。
{
"name": "webscraping_ai_fields",
"arguments": {
"url": "https://example.com/product",
"fields": {
"title": "Extract the product title",
"price": "Extract the product price",
"description": "Extract the product description"
},
"js": true,
"timeout": 30000
}
}
示例响应:
{
"content": [
{
"type": "text",
"text": {
"title": "Example Product",
"price": "$99.99",
"description": "This is an example product description."
}
}
],
"isError": false
}
3. HTML 工具 (webscraping_ai_html
)
获取带有 JavaScript 渲染的网页的完整 HTML。
{
"name": "webscraping_ai_html",
"arguments": {
"url": "https://example.com",
"js": true,
"timeout": 30000,
"wait_for": "#content-loaded"
}
}
示例响应:
{
"content": [
{
"type": "text",
"text": "<html>...[full HTML content]...</html>"
}
],
"isError": false
}
4. 文本工具 (webscraping_ai_text
)
提取网页中可见的文本内容。
{
"name": "webscraping_ai_text",
"arguments": {
"url": "https://example.com",
"js": true,
"timeout": 30000
}
}
示例响应:
{
"content": [
{
"type": "text",
"text": "Example Domain\nThis domain is for use in illustrative examples in documents..."
}
],
"isError": false
}
5. 选择工具 (webscraping_ai_selected
)
使用 CSS 选择器从特定元素中提取内容。
{
"name": "webscraping_ai_selected",
"arguments": {
"url": "https://example.com",
"selector": "div.main-content",
"js": true,
"timeout": 30000
}
}
示例响应:
{
"content": [
{
"type": "text",
"text": "<div class=\"main-content\">This is the main content of the page.</div>"
}
],
"isError": false
}
6. 选择多个工具 (webscraping_ai_selected_multiple
)
使用 CSS 选择器从多个元素中提取内容。
{
"name": "webscraping_ai_selected_multiple",
"arguments": {
"url": "https://example.com",
"selectors": ["div.header", "div.product-list", "div.footer"],
"js": true,
"timeout": 30000
}
}
示例响应:
{
"content": [
{
"type": "text",
"text": [
"<div class=\"header\">Header content</div>",
"<div class=\"product-list\">Product list content</div>",
"<div class=\"footer\">Footer content</div>"
]
}
],
"isError": false
}
7. 账户工具 (webscraping_ai_account
)
获取关于您的 WebScraping.AI 账户的信息。
{
"name": "webscraping_ai_account",
"arguments": {}
}
示例响应:
{
"content": [
{
"type": "text",
"text": {
"requests": 5000,
"remaining": 4500,
"limit": 10000,
"resets_at": "2023-12-31T23:59:59Z"
}
}
],
"isError": false
}
所有工具的通用选项
以下选项可以与所有抓取工具一起使用:
timeout
: 网页检索的最大时间(毫秒)(默认为 15000,最大值为 30000)js
: 使用无头浏览器执行页面上的 JavaScript(默认为 true)js_timeout
: JavaScript 渲染的最大时间(毫秒)(默认为 2000)wait_for
: 返回页面内容之前要等待的 CSS 选择器proxy
: 代理类型,数据中心或住宅(默认为住宅)country
: 要使用的代理的国家/地区(默认为美国)。 支持的国家/地区:us, gb, de, it, fr, ca, es, ru, jp, kr, incustom_proxy
: 您自己的代理 URL,格式为 "http://user:password@host:port"device
: 设备模拟的类型。 支持的值:desktop, mobile, tableterror_on_404
: 在目标页面上出现 404 HTTP 状态时返回错误(默认为 false)error_on_redirect
: 在目标页面上重定向时返回错误(默认为 false)js_script
: 要在目标页面上执行的自定义 JavaScript 代码
错误处理
服务器提供强大的错误处理:
- 自动重试瞬时错误
- 具有退避的速率限制处理
- 详细的错误消息
- 网络弹性
示例错误响应:
{
"content": [
{
"type": "text",
"text": "API Error: 429 Too Many Requests"
}
],
"isError": true
}
与 LLM 集成
此服务器实现了 模型上下文协议,使其与任何支持 MCP 的 LLM 平台兼容。 您可以配置您的 LLM 以使用这些工具进行网页抓取任务。
示例:使用 MCP 配置 Claude
// Example code for connecting Claude with the WebScraping.AI MCP Server
const { Claude } = require('@anthropic-ai/sdk');
const { McpClient } = require('@modelcontextprotocol/sdk/client');
const claude = new Claude({
apiKey: 'your_claude_api_key'
});
const mcpClient = new McpClient({
baseUrl: 'http://localhost:3000/sse'
});
// Now you can use Claude with WebScraping.AI tools
const response = await claude.messages.create({
model: 'claude-3-opus-20240229',
max_tokens: 1000,
system: 'You have access to WebScraping.AI tools for web data extraction.',
messages: [
{ role: 'user', content: 'Extract the main heading from https://example.com' }
],
tools: await mcpClient.listTools()
});
开发
# 克隆仓库
git clone https://github.com/webscraping-ai/webscraping-ai-mcp-server.git
cd webscraping-ai-mcp-server
# 安装依赖
npm install
# 运行测试
npm test
# 添加您的 .env 文件
cp .env.example .env
# 启动检查器
npx @modelcontextprotocol/inspector node src/index.js
贡献
- Fork 仓库
- 创建您的功能分支
- 运行测试:
npm test
- 提交 pull request
许可证
MIT 许可证 - 详细信息请参阅 LICENSE 文件
推荐服务器
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
MCP Package Docs Server
促进大型语言模型高效访问和获取 Go、Python 和 NPM 包的结构化文档,通过多语言支持和性能优化来增强软件开发。
Claude Code MCP
一个实现了 Claude Code 作为模型上下文协议(Model Context Protocol, MCP)服务器的方案,它可以通过标准化的 MCP 接口来使用 Claude 的软件工程能力(代码生成、编辑、审查和文件操作)。
@kazuph/mcp-taskmanager
用于任务管理的模型上下文协议服务器。它允许 Claude Desktop(或任何 MCP 客户端)在基于队列的系统中管理和执行任务。
mermaid-mcp-server
一个模型上下文协议 (MCP) 服务器,用于将 Mermaid 图表转换为 PNG 图像。
Jira-Context-MCP
MCP 服务器向 AI 编码助手(如 Cursor)提供 Jira 工单信息。

Linear MCP Server
一个模型上下文协议(Model Context Protocol)服务器,它与 Linear 的问题跟踪系统集成,允许大型语言模型(LLM)通过自然语言交互来创建、更新、搜索和评论 Linear 问题。

Sequential Thinking MCP Server
这个服务器通过将复杂问题分解为顺序步骤来促进结构化的问题解决,支持修订,并通过完整的 MCP 集成来实现多条解决方案路径。
Curri MCP Server
通过管理文本笔记、提供笔记创建工具以及使用结构化提示生成摘要,从而实现与 Curri API 的交互。