网页抓取服务

一个基于BeautifulSoup和aiohttp的网页抓取服务,提供网页内容提取、链接提取、元数据提取和结构化数据提取功能。

  • by VDliveson
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 VDliveson/MCP-Core

使用说明

Web抓取MCP服务器

一个模型上下文协议服务器,使用BeautifulSoup和aiohttp提供网络抓取功能。

特性

  • scrape_url:使用可选的CSS选择器从任何网页提取文本内容
  • 提取链接:从包含文本和标题的页面获取所有链接
  • 提取元数据:提取页面元数据(标题、描述、Open Graph标记)
  • extract_structured_data:以结构化格式提取表格、标题或列表

安装

  1. 创建虚拟环境:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. 安装依赖项:
pip install -r requirements.txt

用法

运行服务器

python server.py

确保更换 /absolute/path/to/server.py 使用服务器文件的实际路径。

工具示例

1.删除整页内容

Use the scrape_url tool to get the content from https://example.com

2.提取特定元素

Use the scrape_url tool with selector ".article-content" from https://news.example.com

3.获取所有链接

Use the extract_links tool to find all links on https://example.com

4.提取元数据

Use the extract_metadata tool to get metadata from https://example.com

5.提取表格

Use the extract_structured_data tool with type "tables" from https://example.com

依赖项

  • 主控程序:模型上下文协议SDK
  • 美容组4:HTML解析和抓取
  • 意图tp:异步HTTP客户端
  • lxml 文件:快速HTML解析器后端

许可证

MIT许可证