mcp-playwright-scraper 是一个模型上下文协议(MCP)服务器,可用于抓取网页内容并将其转换为 Markdown 格式,为网页内容处理提供了便捷的解决方案。
mcp-playwright-scraper 是一个强大的 MCP 服务器,能够帮助您轻松抓取网页内容并转换为 Markdown 格式。以下将为您详细介绍其使用方法。
scrape_to_markdown 工具,可从指定 URL 抓取内容并转换为 Markdown 格式。该工具使用简单,必要参数仅需 url(字符串),同时还提供可选参数 verify_ssl(布尔值),可根据需求选择是否验证 SSL 证书(默认值为 true)。当使用uv时,无需进行任何特定安装。我们将直接使用uvx运行 mcp-playwright-scraper。
或者,您可以通过 pip 安装 mcp-playwright-scraper:
pip install mcp-playwright-scraper
安装完成后,您可以作为脚本运行:
python -m mcp_playwright_scraper
安装此服务器之前,请确保安装 Playwright 浏览器依赖:
playwright install --with-deps chromium
使用 scrape_to_markdown 工具从指定 URL 抓取内容并转换为 Markdown 格式:
# 假设已经安装并导入了相应的库
# 调用 scrape_to_markdown 工具,传入必要的 url 参数
# 这里的 url 请替换为实际要抓取的网页地址
result = scrape_to_markdown(url="https://example.com")
print(result)
在使用 scrape_to_markdown 工具时,可根据需求设置可选参数 verify_ssl:
# 假设已经安装并导入了相应的库
# 调用 scrape_to_markdown 工具,传入 url 参数和 verify_ssl 参数
# 这里的 url 请替换为实际要抓取的网页地址
# verify_ssl 设置为 False 表示不验证 SSL 证书
result = scrape_to_markdown(url="https://example.com", verify_ssl=False)
print(result)
要将 MCP 服务器添加到 Claude Desktop,请按照以下步骤操作:
mcp-playwright-scraperMCP Serveryour/custom/path/to/mcp-playwright-scraper/executable在Claude Code中使用时,请将以下内容添加到 mcp-servers.json:
{
"mcp-playwright-scraper": {
"type": "MCP Server",
"executablePath": "/path/to/mcp_playwright_scraper_executable"
}
}
要在Zed中使用,请将以下内容添加到 mcp-servers.json:
{
"mcp-playwright-scraper": {
"type": "MCP Server",
"executablePath": "/path/to/mcp_playwright_scraper_executable"
}
}
要在Cursor中使用,请将以下内容添加到 mcp-servers.json:
{
"mcp-playwright-scraper": {
"type": "MCP Server",
"executablePath": "/path/to/mcp_playwright_scraper_executable"
}
}
在 Claude Desktop 中添加 MCP 服务器:
mcp-playwright-scraperMCP Server/path/to/mcp_playwright_scraper_executable您也可以使用以下命令将服务器添加到 mcp-servers.json:
uv add mcp-playwright-scraper --type MCP\ Server --config executablePath="/path/to/executable"
要调试 MCP 服务器,请运行以下命令启动 Inspector:
uv inspect run mcp-playwright-scraper
启动后,您将在控制台中看到一个 URL。将此 URL 复制到浏览器中以开始调试。
准备发行版本:
uv sync
uv build
uv publish
注意:您需要设置 PyPI 凭据,可以通过环境变量或命令行参数完成:
--token 或 UV_PUBLISH_TOKEN--username/UV_PUBLISH_USERNAME 和 --password/UV_PUBLISH_PASSWORD此 MCP 服务器根据 Apache License Version 2.0 授权。您有权自由使用、修改和分发软件,但需遵守 Apache License 2.0 的条款和条件。有关详细信息,请访问 LICENSE 文件或访问 http://www.apache.org/licenses/LICENSE-2.0。