Sponsored by Deepsite.site

小红书热帖获取

Created By
chaseSpace6 months ago
Content

Python-MCP-Server:小红书热帖获取

本项目基于 FastMCP SDK 开发,功能是根据指定“关键词”获取小红书的热帖数据,默认获取5~ 10篇(参数控制),不支持翻页获取。

1. Tools

  • fetch_xhs_hot_post:从小红书获取爆款帖子数据
    • 具体包括每篇帖子的标题、内容、发布时间、标签等数据,请查看 model.py 中的 Post class了解更多。

2. 准备

2.1 环境要求

  • Python 3.12+
  • Chrome浏览器,Centos 安装参考这里

2.2 外部环境变量

由于目标网站需要登录后才可以搜索内容,因为本项目使用了钉钉来接收登录二维码,请先在钉钉群中添加机器人(安全设置选择加签), 并获取必要信息作为环境变量注入环境,如下示例:

# mcp.env
DINGTALK_WEBHOOK_URI=https://oapi.dingtalk.com/robot/send?access_token=YOUR_TOKEN
DINGTALK_SECRET=YOUR_SECRET

将上述环境变量放入项目根目录下的mcp.env文件(自行创建)中即可。

3. 安装运行

注:本项目并未通过 pypi 进行分发,目前仅支持本地部署运行。

  1. 首先Clone本项目,然后使用uv命令安装依赖:
# 若未安装uv,可通过pip等方式安装
cd mcp_fetch_xhs_post
source .venv/Scripts/activate # 激活venv。若是windows cmd环境,则执行 .\.venv\Scripts\activate.bat 

uv sync
  1. 启动:
uv run main.py

4. 添加MCP Server

项目启动后,在所使用的MCP Client添加一个MCP Server,关键配置如下

  • 名称:小红书热帖获取
  • 传输类型:SSE
  • URL:http://127.0.0.1:9090/sse (假设在本机运行MCP Server,端口可在代码中修改)

5. 运行流程

项目启动且成功添加到MCP Client后,就可以开始使用了。

第一次运行时,由于本地的Chrome浏览器可能没有登录小红书PC网站,程序会自动将用于登录的二维码发送至钉钉群中, 请进入钉钉群扫码登陆,程序将会等待30s,如超时工具会自动重试最多3次。登陆成功后,程序也会将登陆成功的消息发送至钉钉群中。 之后会开始获取数据,在启动项目的控制台输出中可以看到运行日志打印。

6. 免责声明

6.1 目的

本项目旨在提供一个教育和研究工具,用于学习和理解MCP、网络爬虫技术的实现和应用。本项目不鼓励或支持任何违反服务条款或法律法规的行为。

6.2 服务条款遵守

使用本项目前,请确保您已经阅读并理解目标网站(如小红书)的服务条款。本项目不保证对目标网站的服务条款完全兼容,使用本项目爬取数据可能违反目标网站的服务条款。

6.3 合法性

用户在使用本项目时应确保其行为符合当地法律法规及目标网站的使用政策。本项目不对因违反法律法规或服务条款而导致的任何后果承担责任。

6.4 数据使用

用户应仅将通过本项目爬取的数据用于合法和正当的目的。不得将数据用于商业目的、侵犯版权、侵犯个人隐私或其他不当用途。

6.5 风险自负

使用本项目爬取数据存在被目标网站封禁或其他形式的反爬措施的风险。用户应自行承担使用本项目可能带来的所有风险。

6.6 开源协议

本项目遵循 MIT License 开源协议。在遵循开源协议的前提下,您可以自由地使用、修改和分发本项目。

6.7 免责声明

本项目“按原样”提供,不提供任何形式的明示或暗示的保证,包括但不限于对适销性、特定用途适用性和非侵权性的保证。在任何情况下, 作者或贡献者均不对因使用本项目而产生的任何直接的、间接的、偶然的、特殊的、惩罚性的或后果性的损害负责,包括但不限于替代商品或服务的采购、 使用、数据或利润的损失,或业务中断,无论此类损害是如何引起的,也无论是否已告知可能发生此类损害的可能性。

6.8 联系方式

如果您对本项目有任何疑问或担忧,或发现本项目可能违反了法律法规或服务条款,请通过Github issue与我联系。

Server Config

{
  "mcpServers": {
    "mcp_fetch_xhs_post": {
      "command": "仅支持本地sse部署",
      "args": [],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>"
      }
    }
  }
}
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Amap Maps高德地图官方 MCP Server
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
ChatWiseThe second fastest AI chatbot™
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Tavily Mcp
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Playwright McpPlaywright MCP server
CursorThe AI Code Editor
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
WindsurfThe new purpose-built IDE to harness magic
Serper MCP ServerA Serper MCP Server
DeepChatYour AI Partner on Desktop