小红书
by @chocomintx
XiaoHongShu (Little Red Book) data collection and interaction toolkit. Use when working with XiaoHongShu (小红书) platform for: (1) Searching and scraping notes/posts, (2) Getting user profiles and details, (3) Extracting comments and likes, (4) Following users and liking posts, (5) Fetching home feed and trending content. Automatically handles all encryption parameters (cookies, headers) including a1, webId, x-s, x-s-common, x-t, sec_poison_id, websectiga, gid, x-b3-traceid, x-xray-traceid. Suppor
clawhub install xiaohongshutools📖 About This Skill
name: xiaohongshu description: "XiaoHongShu (Little Red Book) data collection and interaction toolkit. Use when working with XiaoHongShu (小红书) platform for: (1) Searching and scraping notes/posts, (2) Getting user profiles and details, (3) Extracting comments and likes, (4) Following users and liking posts, (5) Fetching home feed and trending content. Automatically handles all encryption parameters (cookies, headers) including a1, webId, x-s, x-s-common, x-t, sec_poison_id, websectiga, gid, x-b3-traceid, x-xray-traceid. Supports guest mode and authenticated sessions via web_session cookie."
Xiaohongshu Skill
小红书(XiaoHongShu / Little Red Book)数据采集和交互工具包。基于RedCrack纯Python逆向工程实现。
Quick Start
Installation
Dependencies are already installed:
pip install aiohttp loguru pycryptodome getuseragent
Basic Usage
import asyncio
import sys
sys.path.insert(0, r'C:\\Users\\Chocomint\\.openclaw\\workspace\\xiaohongshu\\scripts')from request.web.xhs_session import create_xhs_session
async def main():
# ✅ 推荐:不强制代理(有代理再填 proxy)
# 说明:当前小红书接口经常对“未登录/游客”限制搜索能力。
# 如果 search 报 code=-104(未登录无权限),请提供 web_session。
xhs = await create_xhs_session(proxy=None, web_session="YOUR_WEB_SESSION_OR_NONE")
# Search notes
res = await xhs.apis.note.search_notes("美妆")
data = await res.json()
print(data)
await xhs.close_session()
asyncio.run(main())
Core Capabilities
1. Search & Discovery
Search notes by keyword:
res = await xhs_session.apis.note.search_notes("口红")
Get home feed (trending):
# 注意:get_homefeed 需要 category 参数
res = await xhs_session.apis.note.get_homefeed(
xhs_session.apis.note.homefeed_category_enum.FOOD
)
Get note detail:
# note_detail 需要 note_id + xsec_token(有时在搜索结果 item 里叫 xsec_token)
res = await xhs_session.apis.note.note_detail(note_id, xsec_token)
2. User Interactions
Get user info:
res = await xhs_session.apis.auth.get_self_simple_info()
Follow a user:
res = await xhs_session.apis.user.follow_user(user_id)
Like a note:
res = await xhs_session.apis.note.like_note(note_id)
3. Comments
Get comments for a note:
# comments 也需要 note_id + xsec_token
res = await xhs_session.apis.comments.get_comments(note_id, xsec_token)
Configuration
Proxy
代理不是硬性要求(本技能可以 proxy=None 运行)。但在以下情况建议使用代理:
不使用代理:
xhs = await create_xhs_session(proxy=None, web_session=None)
使用代理:
xhs = await create_xhs_session(
proxy="http://127.0.0.1:7890",
web_session="your_web_session_cookie" # 需要登录能力时再提供
)
Encryption Parameters
All encryption parameters are automatically generated:
Configuration file: scripts/request/web/encrypt/web_encrypt_config.ini
Session Management
Guest Mode (No Login)
xhs_session = await create_xhs_session(proxy="http://127.0.0.1:7890")
Authenticated Mode (With Login)
xhs_session = await create_xhs_session(
proxy="http://127.0.0.1:7890",
web_session="030037afxxxxxxxxxxxxxxxxxxxaeb59d5b4" # Your cookie
)
Close Session
await xhs_session.close_session()
Links & IDs (重要)
697cc945000000000a02cdad。https://www.xiaohongshu.com/explore/?xsec_token=...&xsec_source=pc_search
输出到聊天时的链接美化(推荐)
为了避免长链接难看,优先用文本标签超链接:标题Available APIs
All APIs are accessible via xhs_session.apis.*:
Authentication (apis.auth):
get_self_simple_info() - Get current user infoNotes (apis.note):
search_notes(keyword) - Search notes by keywordget_homefeed(category) - Get home feednote_detail(note_id, share_token) - Get note detailslike_note(note_id) - Like a noteComments (apis.comments):
get_comments(note_id, share_token) - Get note commentsUser (apis.user):
follow_user(user_id) - Follow a userget_user_info(user_id) - Get user detailsExample Workflows
Workflow 1: Search and Extract Notes
async def search_example():
xhs_session = await create_xhs_session(proxy="http://127.0.0.1:7890") # Search for makeup tutorials
res = await xhs_session.apis.note.search_notes("美妆教程")
data = await res.json()
for note in data['data']['items']:
print(f"Title: {note['display_title']}")
print(f"Author: {note['user']['nickname']}")
print(f"Likes: {note['liked_count']}")
print("---")
await xhs_session.close_session()
Workflow 2: Get Comments for Analysis
async def comments_example():
xhs_session = await create_xhs_session(proxy="http://127.0.0.1:7890") note_id = "64f1a2d30000000013003689"
res = await xhs_session.apis.comments.get_comments(note_id, "")
data = await res.json()
for comment in data['data']['comments']:
print(f"User: {comment['user']['nickname']}")
print(f"Content: {comment['content']}")
print(f"Likes: {comment['like_count']}")
print("---")
await xhs_session.close_session()
Workflow 3: User Profile Analysis
async def profile_example():
xhs_session = await create_xhs_session(
proxy="http://127.0.0.1:7890",
web_session="your_cookie_here"
) # Get self info
res = await xhs_session.apis.auth.get_self_simple_info()
data = await res.json()
print(f"Username: {data['data']['user']['nickname']}")
print(f"Followers: {data['data']['user']['follows']}")
print(f"Fans: {data['data']['user']['fans']}")
await xhs_session.close_session()
Important Notes
1. Proxy is required for most operations due to XiaoHongShu's anti-scraping measures 2. Rate limiting: Be respectful with request frequency to avoid IP bans 3. Authentication: Some operations require login (web_session cookie) 4. Legal compliance: Use only for legitimate research and data analysis purposes
Technical Details
Based on RedCrack - Pure Python reverse engineering of XiaoHongShu's encryption algorithms.
What's automatically handled:
No JavaScript runtime required - All encryption is pure Python.
Troubleshooting
Connection errors
461 errors(风控/安全校验)
OtherStatusError: 461异常,或者接口返回看似 success=true 但 HTTP=461。应对建议:
401/403 errors
Import errors
pip install aiohttp loguru pycryptodome getuseragentsys.path.insert()💡 Examples
Installation
Dependencies are already installed:
pip install aiohttp loguru pycryptodome getuseragent
Basic Usage
import asyncio
import sys
sys.path.insert(0, r'C:\\Users\\Chocomint\\.openclaw\\workspace\\xiaohongshu\\scripts')from request.web.xhs_session import create_xhs_session
async def main():
# ✅ 推荐:不强制代理(有代理再填 proxy)
# 说明:当前小红书接口经常对“未登录/游客”限制搜索能力。
# 如果 search 报 code=-104(未登录无权限),请提供 web_session。
xhs = await create_xhs_session(proxy=None, web_session="YOUR_WEB_SESSION_OR_NONE")
# Search notes
res = await xhs.apis.note.search_notes("美妆")
data = await res.json()
print(data)
await xhs.close_session()
asyncio.run(main())
⚙️ Configuration
Proxy
代理不是硬性要求(本技能可以 proxy=None 运行)。但在以下情况建议使用代理:
不使用代理:
xhs = await create_xhs_session(proxy=None, web_session=None)
使用代理:
xhs = await create_xhs_session(
proxy="http://127.0.0.1:7890",
web_session="your_web_session_cookie" # 需要登录能力时再提供
)
Encryption Parameters
All encryption parameters are automatically generated:
Configuration file: scripts/request/web/encrypt/web_encrypt_config.ini
📋 Tips & Best Practices
Connection errors
461 errors(风控/安全校验)
OtherStatusError: 461异常,或者接口返回看似 success=true 但 HTTP=461。应对建议:
401/403 errors
Import errors
pip install aiohttp loguru pycryptodome getuseragentsys.path.insert()