返回市场
MCP-Playwright爬虫服务器

MCP-Playwright爬虫服务器

作者:dennisgl5 星标更新:2025-03-09

项目介绍

mcp-playwright-scraper

一个用于抓取网页内容并将其转换为Markdown格式的Model Context Protocol (MCP)服务器。

概述

此MCP服务器提供了一个简单的工具,用于抓取网页内容并将其转换为Markdown格式。它使用了以下工具:

  • Playwright:用于无头浏览器自动化处理现代网页,包括JavaScript密集型网站。
  • BeautifulSoup:用于HTML解析和清理。
  • Pypandoc:用于高质量的HTML到Markdown转换。

工具

该服务器实现了一个单一工具:

  • scrape_to_markdown:从URL抓取内容并将其转换为Markdown。
    • 必需参数:url(字符串) - 要抓取的URL。
    • 可选参数:verify_ssl(布尔值) - 是否验证SSL证书(默认:true)。

安装

使用uv(推荐)

当使用uv时,不需要特定的安装步骤。我们将使用uvx直接运行mcp-playwright-scraper

使用PIP

或者,你可以通过pip安装mcp-playwright-scraper

pip install mcp-playwright-scraper

安装后,可以使用以下命令作为脚本运行:

python -m mcp_playwright_scraper

先决条件

  • Python 3.11或更高版本
  • Playwright浏览器依赖项
  • Pandoc(可选,如果可能,pypandoc会自动安装)

安装后,需要安装Playwright浏览器依赖项:

playwright install --with-deps chromium

配置

与Claude Desktop一起使用

在你的claude_desktop_config.json中添加以下内容:

<details> <summary>使用uvx</summary>
"mcpServers": {
  "mcp-playwright-scraper": {
    "command": "uvx",
    "args": ["mcp-playwright-scraper"]
  }
}
</details> <details> <summary>使用pip安装</summary>
"mcpServers": {
  "m- cp-playwright-scraper": {
    "command": "python",
    "args": ["-m", "mcp_playwright_scraper"]
  }
}
</details>

与Claude Code一起使用

# 基本语法
$ claude mcp add mcp-playwright-scraper -- uvx mcp-playwright-scraper

# 或者,使用pip安装
$ claude mcp add mcp-playwright-scraper -- python -m mcp_playwright_scraper
<details> <summary>开发/未发布的服务器配置</summary>
"mcpServers": {
  "mcp-playwright-scraper": {
    "command": "uv",
    "args": [
      "--directory",
      "/path/to/mcp-playwright-scraper",
      "run",
      "mcp-playwright-scraper"
    ]
  }
}
</details>

Zed一起使用

在你的Zed settings.json中添加以下内容:

<details> <summary>使用uvx</summary>
"context_servers": [
  "mcp-playwright-scraper": {
    "command": {
      "path": "uvx",
      "args": ["mcp-playwright-scraper"]
    }
  }
],
</details> <details> <summary>使用pip安装</summary>
"context_servers": {
  "mcp-playwright-scraper": {
    "command": "python",
    "args": ["-m", "mcp_playwright_scraper"]
  }
},
</details>

与Cursor一起使用

  1. 打开Cursor设置
    • 导航至Cursor设置 > 功能 > MCP
    • 点击“+ 添加新MCP服务器”按钮
  2. 配置服务器
    • 名称:mcp-playwright-scraper
    • 类型:选择stdio
    • 命令:输入以下之一:
<details> <summary>使用uvx</summary>
uvx mcp-playwright-scraper
</details> <details> <summary>使用pip安装</summary>
python -m mcp_playwright_scraper
</details>

使用方法

一旦在Claude Desktop中配置好,你可以通过提示明确使用抓取器:

使用mcp-playwright-scraper从https://example.com抓取内容并总结。

调试

你可以使用MCP检查器来调试服务器:

npx @modelcontextprotocol/inspector uvx mcp-playwright-scraper

或者,如果你在一个特定目录中安装了包或正在开发它:

cd path/to/mcp-playwright-scraper
npx @modelcontextprotocol/inspector uv run mcp-playwright-scraper

启动后,检查器将在浏览器中显示一个URL,以便开始调试。

开发

构建和发布

为了准备分发包:

  1. 同步依赖项并更新锁文件:
uv sync
  1. 构建包分布:
uv build

这将在dist/目录中创建源和轮子分布。

  1. 发布到PyPI:
uv publish

注意:你需要通过环境变量或命令标志设置PyPI凭证:

  • Token:--tokenUV_PUBLISH_TOKEN
  • 或用户名/密码:--username/UV_PUBLISH_USERNAME--password/UV_PUBLISH_PASSWORD

许可证

此MCP服务器根据Apache许可证2.0版授权。你可以自由使用、修改和分发软件,但须遵守Apache许可证2.0的条款和条件。更多详情,请参阅项目存储库中的LICENSE文件或访问http://www.apache.org/licenses/LICENSE-2.0。