WebScraping.AI数据提取服务器

@webscraping-ai/webscraping-ai-mcp-server
0 Stars 358 次浏览 webscraping-ai 更新于 2026-08-23

与WebScraping.AI API进行交互,以进行网络数据提取和抓取。

该服务暂未提供标准配置,请参考 README 手动接入

服务介绍

WebScraping.AI MCP 服务器

这是一个实现了 Model Context Protocol (MCP) 的服务器,它与 WebScraping.AI 集成,以提供网页数据提取功能。

特性

  • 关于网页内容的问题回答
  • 从网页中提取结构化数据
  • 使用 JavaScript 渲染的 HTML 内容检索
  • 从网页中提取纯文本
  • 基于 CSS 选择器的内容提取
  • 多种代理类型(数据中心、住宅)并可选择国家
  • 使用无头 Chrome/Chromium 进行 JavaScript 渲染
  • 并发请求管理和速率限制
  • 在目标页面上执行自定义 JavaScript
  • 设备模拟(桌面、移动设备、平板电脑)
  • 账户使用情况监控

安装

使用 npx 运行

env WEBSCRAPING_AI_API_KEY=your_api_key npx -y webscraping-ai-mcp

手动安装

# Clone the repository
git clone https://github.com/webscraping-ai/webscraping-ai-mcp-server.git
cd webscraping-ai-mcp-server

# Install dependencies
npm install

# Run
npm start

在 Cursor 中配置

注意:需要 Cursor 版本 0.45.6+

WebScraping.AI MCP 服务器可以在 Cursor 中通过两种方式配置:

  1. 项目特定配置(推荐用于团队项目):
    在您的项目目录中创建一个 .cursor/mcp.json 文件:

    {
      "servers": {
        "webscraping-ai": {
          "type": "command",
          "command": "npx -y webscraping-ai-mcp",
          "env": {
            "WEBSCRAPING_AI_API_KEY": "your-api-key",
            "WEBSCRAPING_AI_CONCURRENCY_LIMIT": "5"
          }
        }
      }
    }
    
  2. 全局配置(适用于个人在所有项目中的使用):
    在您的主目录中创建一个 ~/.cursor/mcp.json 文件,其配置格式与上述相同。

如果您使用的是 Windows 并遇到问题,请尝试使用 cmd /c "set WEBSCRAPING_AI_API_KEY=your-api-key && npx -y webscraping-ai-mcp" 作为命令。

此配置将在相关网络抓取任务时自动使 WebScraping.AI 工具对 Cursor 的 AI 代理可用。

在 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_CONCURRENCY_LIMIT: 最大并发请求数(默认: 5
  • WEBSCRAPING_AI_DEFAULT_PROXY_TYPE: 使用的代理类型(默认: residential
  • WEBSCRAPING_AI_DEFAULT_JS_RENDERING: 启用/禁用 JavaScript 渲染(默认: true
  • WEBSCRAPING_AI_DEFAULT_TIMEOUT: 最大网页检索时间(毫秒,默认: 15000,最大: 30000
  • WEBSCRAPING_AI_DEFAULT_JS_TIMEOUT: 最大 JavaScript 渲染时间(毫秒,默认: 2000

配置示例

对于标准用途:

# Required
export WEBSCRAPING_AI_API_KEY=your-api-key

# Optional - customize behavior (default values)
export WEBSCRAPING_AI_CONCURRENCY_LIMIT=5
export WEBSCRAPING_AI_DEFAULT_PROXY_TYPE=residential # datacenter or residential
export WEBSCRAPING_AI_DEFAULT_JS_RENDERING=true
export WEBSCRAPING_AI_DEFAULT_TIMEOUT=15000
export WEBSCRAPING_AI_DEFAULT_JS_TIMEOUT=2000

可用工具

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)。支持的国家:us, gb, de, it, fr, ca, es, ru, jp, kr, in
  • custom_proxy: 您自己的代理 URL,格式为 "http://user:password@host:port"
  • device: 设备模拟类型。支持的值:desktop, mobile, tablet
  • error_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 的集成

该服务器实现了 Model Context Protocol,使其与任何启用 MCP 的 LLM 平台兼容。您可以配置您的 LLM 使用这些工具来执行网页抓取任务。

示例:使用 MCP 配置 Claude

const { Claude } = require('@anthropic-ai/sdk');
const { Client } = require('@modelcontextprotocol/sdk/client/index.js');
const { StdioClientTransport } = require('@modelcontextprotocol/sdk/client/stdio.js');

const claude = new Claude({
  apiKey: process.env.ANTHROPIC_API_KEY
});

const transport = new StdioClientTransport({
  command: 'npx',
  args: ['-y', 'webscraping-ai-mcp'],
  env: {
    WEBSCRAPING_AI_API_KEY: 'your-api-key'
  }
});

const client = new Client({
  name: 'claude-client',
  version: '1.0.0'
});

await client.connect(transport);

// Now you can use Claude with WebScraping.AI tools
const tools = await client.listTools();
const response = await claude.complete({
  prompt: 'What is the main topic of example.com?',
  tools: tools
});

开发

# Clone the repository
git clone https://github.com/webscraping-ai/webscraping-ai-mcp-server.git
cd webscraping-ai-mcp-server

# Install dependencies
npm install

# Run tests
npm test

# Add your .env file
cp .env.example .env

# Start the inspector
npx @modelcontextprotocol/inspector node src/index.js

贡献

  1. 分叉仓库
  2. 创建您的功能分支
  3. 运行测试:npm test
  4. 提交拉取请求

许可证

MIT 许可证 - 详情请参阅 LICENSE 文件

相关 MCP 服务