loading…
Search for a command to run...
loading…
Enables AI agents to crawl, access, and analyze WeChat Official Account articles using Selenium and the Model Context Protocol. It provides specialized tools fo
Enables AI agents to crawl, access, and analyze WeChat Official Account articles using Selenium and the Model Context Protocol. It provides specialized tools for dynamic content retrieval, image processing, and automated article analysis.
基于 FastMCP 框架构建的微信公众号文章爬虫系统,让AI智能体能够直接访问和分析微信公众号内容。通过MCP (Model Context Protocol) 标准协议,实现AI智能体与Selenium爬虫的无缝集成。
在使用AI平台或智能体时,我们发现智能体无法直接访问微信公众号文章内容。为了解决这个问题,我们开发了这个基于MCP协议的爬虫服务,让AI智能体能够获取和分析微信公众号的内容。
graph TB
subgraph "AI智能体层"
A[Claude Desktop]
B[ChatGPT]
C[其他AI智能体]
end
subgraph "MCP协议层"
D[MCP客户端]
E[stdio通信]
F[MCP服务器<br/>FastMCP]
end
subgraph "爬虫引擎层"
G[Selenium WebDriver]
H[Chrome浏览器]
I[图片下载器]
end
subgraph "数据存储层"
J[JSON文件]
K[TXT文件]
L[图片文件]
end
A --> D
B --> D
C --> D
D <--> E
E <--> F
F --> G
G --> H
F --> I
G --> J
G --> K
I --> L
src/mcp_weixin_spider/server.py)src/mcp_weixin_spider/client.py)src/mcp_weixin_spider/__main__.py)src/mcp_weixin_spider/config.py)src/mcp_weixin_spider/spider.py)src/mcp_weixin_spider/spider.py)MCPWeChatOfficialAccounts/
├── src/
│ └── mcp_weixin_spider/
│ ├── __init__.py # 包初始化文件
│ ├── __main__.py # 模块入口点
│ ├── client.py # MCP客户端实现
│ ├── config.py # 配置管理
│ ├── exceptions.py # 异常定义
│ ├── main.py # 主函数
│ ├── server.py # FastMCP服务器实现
│ └── spider.py # Selenium爬虫引擎
├── weixin_spider.py # 爬虫测试脚本
├── config.toml # 主配置文件
├── config.toml.example # 配置文件示例
├── LICENSE # 许可证文件
├── pyproject.toml # 项目元数据和依赖管理
└── README.md # 项目文档
# 1. 克隆项目
git clone https://github.com/example/mcp-weixin-spider.git
cd MCPWeChatOfficialAccounts
# 2. 安装依赖
pip install .
# 3. 开发模式安装(可选,用于开发人员)
pip install -e .[dev]
# 安装最新版本
pip install mcp-weixin-spider
项目使用TOML格式的配置文件,支持通过配置文件和环境变量进行配置。
配置文件说明:
[spider]
headless = true # 是否使用无头模式运行浏览器
wait_time = 10 # 页面等待时间(秒)
download_images = true # 是否下载文章中的图片
browser = "chrome" # 浏览器类型,支持'chrome'和'edge'
chrome_driver_path = "" # ChromeDriver路径(可选,自动管理时可留空)
edge_driver_path = "" # EdgeDriver路径(可选,自动管理时可留空)
articles_dir = ".temp" # 文章保存目录
images_dir = ".images" # 图片保存目录
[mcp]
server_name = "mcp-weixin-spider" # MCP服务器名称
transport = "stdio" # 传输方式(stdio或tcp)
debug = false # 是否启用调试模式
[log]
level = "INFO" # 日志级别(DEBUG, INFO, WARNING, ERROR, CRITICAL)
format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s" # 日志格式
file = "" # 日志文件路径(可选,留空则输出到控制台)
支持通过环境变量覆盖配置文件中的设置:
| 环境变量 | 对应配置项 | 说明 |
|---|---|---|
| HEADLESS | spider.headless | 是否使用无头模式 |
| DOWNLOAD_IMAGES | spider.download_images | 是否下载图片 |
| WAIT_TIME | spider.wait_time | 页面等待时间 |
| BROWSER | spider.browser | 浏览器类型(chrome或edge) |
| CHROME_DRIVER_PATH | spider.chrome_driver_path | ChromeDriver路径(可选) |
| EDGE_DRIVER_PATH | spider.edge_driver_path | EdgeDriver路径(可选) |
| ARTICLES_DIR | spider.articles_dir | 文章保存目录 |
| IMAGES_DIR | spider.images_dir | 图片保存目录 |
| MCP_SERVER_NAME | mcp.server_name | MCP服务器名称 |
| MCP_TRANSPORT | mcp.transport | 传输方式(stdio或tcp) |
| MCP_DEBUG | mcp.debug | 是否启用调试模式 |
| LOG_LEVEL | log.level | 日志级别 |
| LOG_FILE | log.file | 日志文件路径 |
# 启动MCP服务器(默认模式)
mcp-weixin-spider
# 启动MCP服务器(默认模式)
python -m mcp_weixin_spider
# 启动MCP服务器(显式指定server模式)
python -m mcp_weixin_spider server
# 启动交互式客户端
python -m mcp_weixin_spider client
# 运行爬虫测试脚本
python weixin_spider.py
| 工具名称 | 功能描述 | 参数 | 返回值 |
|---|---|---|---|
crawl_weixin_article |
爬取微信公众号文章 | url: 文章URLdownload_images: 是否下载图片custom_filename: 自定义文件名 |
包含文章内容的JSON对象 |
analyze_article |
分析文章内容 | article_content: 文章内容 |
分析结果(关键词、统计信息等) |
get_article_stats |
获取文章统计信息 | article_content: 文章内容 |
文章统计数据 |
# 克隆项目
git clone https://github.com/example/mcp-weixin-spider.git
cd MCPWeChatOfficialAccounts
# 安装开发依赖
pip install -e .[dev]
# 运行代码格式化
black src/ weixin_spider.py
# 运行代码检查
flake8 src/ weixin_spider.py
# 运行类型检查
mypy src/
# 构建项目
python -m build
# 生成的包文件将位于 dist/ 目录
# 运行爬虫测试
python weixin_spider.py
Apache License 2.0
Добавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"mcp-wechat-official-accounts-spider": {
"command": "npx",
"args": []
}
}
}