技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
xiaohongshu【数据与研究】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 encr…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
小红书(XiaoHongShu / Little Red Book)数据采集和交互工具包。基于RedCrack纯Python逆向工程实现。
Dependencies are already installed:
pip install aiohttp loguru pycryptodome getuseragent
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())
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)
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)
Get comments for a note:
# comments 也需要 note_id + xsec_token
res = await xhs_session.apis.comments.get_comments(note_id, xsec_token)
代理不是硬性要求(本技能可以 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" # 需要登录能力时再提供
)
All encryption parameters are automatically generated:
Configuration file: scripts/request/web/encrypt/web_encrypt_config.ini
xhs_session = await create_xhs_session(proxy="http://127.0.0.1:7890")
xhs_session = await create_xhs_session(
proxy="http://127.0.0.1:7890",
web_session="030037afxxxxxxxxxxxxxxxxxxxaeb59d5b4" # Your cookie
)
await xhs_session.close_session()
697cc945000000000a02cdad。https://www.xiaohongshu.com/explore/<note_id>?xsec_token=...&xsec_source=pc_search为了避免长链接难看,优先用文本标签超链接:
[标题](https://www.xiaohongshu.com/explore/...)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 detailsasync 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()
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()
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()
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.
OtherStatusError: 461异常,或者接口返回看似 success=true 但 HTTP=461。应对建议:
pip install aiohttp loguru pycryptodome getuseragentsys.path.insert()