
Xhs Toolkit
STDIOXiaohongshu creator automation toolkit with MCP protocol integration for AI-powered content creation
Xiaohongshu creator automation toolkit with MCP protocol integration for AI-powered content creation
一个强大的小红书自动化工具包,支持通过MCP协议与AI客户端(如Claude Desktop等)集成,实现与AI对话即可进行内容创作、发布及创作者数据分析。
在Chrome浏览器中访问:chrome://version/
# 使用webdriver-manager自动管理 pip install webdriver-manager
/usr/local/bin/
或 C:\tools\
).env
文件中配置正确路径# macOS (Homebrew) brew install --cask chromedriver # Windows (Chocolatey) choco install chromedriver # Linux (Ubuntu/Debian) sudo apt-get install chromium-chromedriver
⚠️ 重要提示:版本不匹配是最常见的问题原因,请确保ChromeDriver版本与Chrome浏览器版本完全一致!
支持连接到已运行的远程Chrome实例,提高性能和支持远程部署场景。
在 .env
文件中添加以下配置:
# 启用远程浏览器连接 ENABLE_REMOTE_BROWSER=true REMOTE_BROWSER_HOST=http://xx.xx.xx.xx REMOTE_BROWSER_PORT=xxxx
./chrome-data
目录是否存在切查看是否有读写权限,如果没有读写权限,请按照下面的步骤修复
docker run --rm selenium/standalone-chrome id seluser
获取seluser的uid,例如返回 uid=1200(seluser) gid=1200(seluser) groups=1200(seluser)
sudo chown -R 1200:1200 ./chrome-data
赋予seluser的读写权限,1200是seluser的uiddocker-compose up --force-recreate
启动容器version: '3.8' services: selenium-chrome: image: selenium/standalone-chrome:latest container_name: selenium-chrome ports: - "54444:4444" - "57900:7900" shm_size: 2g environment: - SE_VNC_NO_PASSWORD=1 volumes: - ./chrome-data:/home/seluser # 更换挂载路径,确保权限 restart: unless-stopped command: > bash -c "mkdir -p /home/seluser/.config/google-chrome && touch /home/seluser/.config/google-chrome/test.txt && /opt/bin/entry_point.sh"
# 克隆项目 git clone https://github.com/aki66938/xhs-toolkit.git cd xhs-toolkit # 运行(会自动安装依赖) ./xhs # Mac/Linux xhs.bat # Windows # 或使用 Python python install_deps.py # 安装依赖向导 ./xhs # 启动程序
运行 ./xhs
后会显示友好的菜单界面:
╭─────────────────────────────────────────╮
│ 小红书MCP工具包 v1.3.0 │
│ 快速操作菜单系统 │
╰─────────────────────────────────────────╯
【主菜单】
1. 🔄 数据收集
2. 🌐 浏览器操作
3. 📊 数据管理
4. 🍪 Cookie管理
5. 🚀 MCP服务器
6. ⚙️ 系统工具
0. 退出
# 克隆项目 git clone https://github.com/aki66938/xhs-toolkit.git cd xhs-toolkit # 使用uv安装依赖并运行 uv sync uv run python xhs_toolkit.py status ## 验证工具是否可用
💡 uv使用提示:文档中所有
python
命令都可以用uv run python
替代,享受更快的依赖管理体验!
# 克隆项目 git clone https://github.com/aki66938/xhs-toolkit.git cd xhs-toolkit # 创建虚拟环境(推荐) python -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate # 安装依赖 pip install -r requirements.txt python xhs_toolkit.py status ## 验证工具是否可用
复制并编辑配置文件:
cp env_example .env vim .env # 编辑配置
必需配置:
# Chrome浏览器路径 CHROME_PATH="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" # ChromeDriver路径 WEBDRIVER_CHROME_DRIVER="/opt/homebrew/bin/chromedriver"
# 方式一:使用交互式菜单 ./xhs # 选择 4 -> Cookie管理 -> 1 -> 获取新的Cookies # 方式二:直接命令 ./xhs cookie save
在弹出的浏览器中, 如果是连接的远程浏览器,可以访问 http://ip:57900 访问vnc界面,然后执行下面的步骤:
# 方式一:使用交互式菜单 ./xhs # 选择 5 -> MCP服务器 -> 1 -> 启动服务器 # 方式二:直接命令 ./xhs server start
Claude Desktop
在 ~/Library/Application Support/Claude/claude_desktop_config.json
中添加:
{ "mcpServers": { "xhs-toolkit": { "command": "uv", "args": [ "--directory", "/path/to/xhs-toolkit", "run", "python", "-m", "src.server.mcp_server", "--stdio" ] } } }
如果不使用 uv,可以配置为:
{ "mcpServers": { "xhs-toolkit": { "command": "python3", "args": [ "-m", "src.server.mcp_server", "--stdio" ], "cwd": "/path/to/xhs-toolkit", "env": { "PYTHONPATH": "/path/to/xhs-toolkit" } } } }
注意:
/path/to/xhs-toolkit
替换为实际的项目路径~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
cherry studio
在MCP配置中添加
n8n
在n8n的AI agent节点的tool中添加配置配置
工具名称 | 功能说明 | 参数 | 备注 |
---|---|---|---|
test_connection | 测试MCP连接 | 无 | 连接状态检查 |
smart_publish_note | 发布小红书笔记 ⚡ | title, content, images, videos, tags, topics | 支持本地路径、网络URL、话题标签 |
check_task_status | 检查发布任务状态 | task_id | 查看任务进度 |
get_task_result | 获取已完成任务的结果 | task_id | 获取最终发布结果 |
login_xiaohongshu | 智能登录小红书 | force_relogin, quick_mode | MCP专用无交互登录 |
get_creator_data_analysis | 获取创作者数据用于分析 | 无 | AI数据分析专用 |
通过与AI对话即可完成登录、发布、数据分析等操作,无需学习复杂命令。
用户:"登录小红书"
重要提示:
headless
参数,获取到cookies后再更改为无头模式图文发布(本地图片):
请发布一篇小红书笔记,标题:"今日分享",内容:"...",图片路径:"/User/me/xhs/poster.png"
图文发布(网络图片):
请发布一篇小红书笔记,标题:"美食分享",内容:"今天的美食",使用这个网络图片:https://example.com/food.jpg
视频发布:
请发布一篇小红书视频,标题:"今日vlog",内容:"...",视频路径:"/User/me/xhs/video.mp4"
带话题标签发布:
请发布一篇小红书笔记,标题:"AI学习心得",内容:"今天学习了机器学习基础",话题:"AI,人工智能,学习心得",图片:"/path/to/image.jpg"
请分析我的小红书账号数据,给出内容优化建议
手工上传过程中,浏览器会弹窗让用户选中文件路径,AI会将用户提供的路径参数传递给MCP工具,自动完成上传动作。
自动采集小红书创作者数据,支持定时任务和AI智能分析。
get_creator_data_analysis
MCP工具获取完整数据采用cron语法,写入配置文件.env
# 每6小时采集一次 COLLECTION_SCHEDULE=0 */6 * * * # 工作日上午9点采集 COLLECTION_SCHEDULE=0 9 * * 1-5 # 每月1号凌晨2点采集 COLLECTION_SCHEDULE=0 2 1 * *
新增交互式菜单和手动操作工具,提供更便捷的操作体验:
# 启动交互式菜单 ./xhs # 或使用命令行 ./xhs manual collect --type all # 收集所有数据 ./xhs manual browser --page publish # 打开发布页面 ./xhs manual export --format excel # 导出Excel ./xhs manual analyze # 分析数据趋势
data-topic
属性和隐藏标识,确保话题获得平台流量推荐topic_automation.py
专用模块,提供基础和高级自动化功能send_keys
无法触发下拉菜单的问题# 新的话题功能使用(MCP工具中自动支持) smart_publish_note( title="AI学习心得", content="分享一些人工智能学习经验", topics=["AI", "人工智能", "学习心得"], # 新增话题参数 images=["image.jpg"] )
./xhs
,无需记忆复杂命令install_deps.py
安装向导./xhs
ImageProcessor
模块统一处理各种图片输入["local.jpg", "https://example.com/img.jpg"]
# 网络图片 smart_publish_note( title="美食分享", content="今天的美食", images=["https://example.com/food.jpg"] ) # 混合使用 smart_publish_note( title="旅行记录", content="风景很美", images=["/local/photo.jpg", "https://example.com/view.jpg"] )
--headless=new
和--headless
双重无头模式配置--disable-gpu-compositing
、--disable-notifications
等多个Chrome参数smart_parse_file_paths()
函数,使用JSON解析、ast.literal_eval等多种解析方式支持的输入格式:
"a.jpg,b.jpg,c.jpg"
"[a.jpg,b.jpg,c.jpg]"
'["a.jpg","b.jpg","c.jpg"]'
["a.jpg", "b.jpg", "c.jpg"]
"[a.jpg,'b.jpg',\"c.jpg\"]"
selenium.common.exceptions.SessionNotCreatedException: session not created: This version of ChromeDriver only supports Chrome version XX
✅ 解决方案:
chrome://version/
.env
文件中的路径配置selenium.common.exceptions.WebDriverException: 'chromedriver' executable needs to be in PATH
✅ 解决方案:
.env
中配置完整路径:WEBDRIVER_CHROME_DRIVER="/path/to/chromedriver"
chmod +x chromedriver
selenium.common.exceptions.WebDriverException: unknown error: cannot find Chrome binary
✅ 解决方案:在 .env
文件中配置正确的Chrome路径
# macOS CHROME_PATH="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" # Windows CHROME_PATH="C:\Program Files\Google\Chrome\Application\chrome.exe" # Linux CHROME_PATH="/usr/bin/google-chrome"
✅ 解决方案:
python xhs_toolkit.py server start
✅ 解决方案:
xhs_cookies.json
文件python xhs_toolkit.py cookie save
感谢所有为项目做出贡献的人!
如果您也想为项目做出贡献,欢迎提交 Pull Request 或 Issue!
本项目基于 MIT许可证 开源。