From rednote-mining
小红书数据挖掘与分析工作流。当用户想对某个主题进行小红书内容研究、数据采集、舆情分析时触发。例如:"帮我分析小红书上关于XX的内容"、"搜索小红书XX话题并出报告"、"用小红书数据研究XX"、"挖掘小红书上XX相关的笔记"。遇到任何需要从小红书获取真实用户观点、做话题分析、地点推荐、产品评测聚合的需求,都应使用此 skill。
How this skill is triggered — by the user, by Claude, or both
Slash command
/rednote-mining:rednote-researchThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
**两个目录概念:**
两个目录概念:
PLUGIN_DIR:插件代码所在 cache 目录(只用于运行脚本)WORK_DIR:用户当前工作目录(分析结果 analysis/ 保存在此)运行命令前先定位并记录两个目录:
PLUGIN_DIR=$(find ~/.claude/plugins/cache/rednote-mining -name "pyproject.toml" 2>/dev/null | head -1 | xargs dirname)
WORK_DIR=$(pwd)
echo "插件目录: $PLUGIN_DIR"
echo "工作目录: $WORK_DIR"
若找不到(未通过市场安装),提示用户安装方法:
/plugin marketplace add xueyouluo/rednote_mining
/plugin install rednote-mining@rednote-mining
再运行 /rednote-mining:setup。
定位到两个目录后,检查当前项目是否已配置 Bash 权限白名单:
cat "$WORK_DIR/.claude/settings.json" 2>/dev/null || echo "NOT_FOUND"
permissions.allow 配置 → 跳过此步骤,直接进入环境初始化"此工作流需要执行多条 Bash 命令(启动爬取脚本、查看日志、运行分析等),每条命令默认都需要手动确认。
是否将常用命令加入项目权限白名单,避免频繁点击确认?
(权限文件保存在 {WORK_DIR}/.claude/settings.json,仅对当前项目生效,不影响全局设置)"
选项:是,自动配置权限(推荐) / 否,每次手动确认
若用户选择"是":
先读取 $WORK_DIR/.claude/settings.json(若存在)以便合并已有配置,再用 Write 工具写入:
{
"permissions": {
"allow": [
"Bash(find *)",
"Bash(mkdir *)",
"Bash(echo *)",
"Bash(tail *)",
"Bash(wc *)",
"Bash(cat *)",
"Bash(cd * && uv run python *)",
"Bash(cd * && nohup uv run python *)",
"Bash(nohup *)",
"Bash(if *)"
]
}
}
注意:若文件已存在,需将上面的 allow 列表与原有 allow 数组合并,不要覆盖已有条目。
写入后提示用户:"权限已配置,后续 Bash 命令将自动执行,无需逐条确认。"
若用户选择"否":跳过,后续命令仍需手动确认。
在执行任何步骤前,先确认以下环境就绪:
每次运行前必须验证登录状态,避免爬取时才发现未登录导致数据为空。
cd "$PLUGIN_DIR" && uv run python -m rednote_miner.rednote_miner search --keyword "测试" --limit 3 --output /tmp/xhs_login_check.json 2>&1
检查输出:
笔记 或 /tmp/xhs_login_check.json 写入成功且内容非空 → 已登录,继续登录、sign in、请登录,或文件为空 → 未登录运行失败处理:
使用/rednote-mining:setup命令引导用户完成登录。
未登录时的处理流程:
使用 AskUserQuestion 告知用户:
"检测到小红书未登录,Chrome 已自动打开,请在浏览器中完成登录后告诉我。"
选项:已完成登录
用户点击后,重新执行上面的检测命令确认登录成功,再继续。
Cookie 持久保存在 ~/.chrome-xhs-profile,之后每次运行无需重复登录。
Step 1: 生成关键词 → 用户确认参数
Step 2: 爬取笔记与评论 → raw_notes.json
Step 3: LLM 分析样本,提出 schema → 用户确认
Step 4: LLM 批量提取结构化数据 → extracted_data.json
Step 5: LLM 实体归一化合并 → normalized_data.json
Step 6: Claude 自己分析 → report.md 或 report.html
所有中间文件保存在用户工作目录的 analysis/{topic_slug}/ 下(即 $WORK_DIR/analysis/{topic_slug}/)。若文件已存在则跳过该步骤(用 AskUserQuestion 询问是否重新生成)。
从用户输入中提取分析主题(如"杭州赏花"、"上海咖啡店"、"防晒霜推荐")。 如果意图不清晰,直接询问用户。
将主题转为目录名:topic_slug = 主题的拼音或英文简写(如 hangzhou_flowers、shanghai_cafe)。
基于主题自行生成 4-6 个搜索关键词(不调用 LLM API,由 Claude 直接生成)。 关键词应覆盖:核心词、长尾词、口语化表达、攻略/推荐类词。
使用 AskUserQuestion 工具,一次询问三个问题:
10篇(快速) / 20篇(推荐) / 50篇(全面)10条(快速) / 20条(推荐) / 50条(深度)关键词问题设置 multiSelect: true,用户可通过空格多选。若用户未选任何关键词,使用全部候选关键词。
必须等用户完成所有选择后才能继续。
若 $WORK_DIR/analysis/{topic_slug}/raw_notes.json 已存在,使用 AskUserQuestion 询问:
"检测到已有采集数据,是否重新采集?"
选项:跳过(使用已有数据)/ 重新采集
根据主题性质自动选择排序方式({sort_by}):
综合:适合大多数主题(默认,兼顾质量与数量)最新:适合时效性强的主题(新品、活动、节日、当季)最多点赞:适合需要高质量内容的主题(攻略、测评、经验分享)最多评论:适合舆情分析、争议话题用户确认后,后台启动爬取脚本:
mkdir -p "$WORK_DIR/analysis/{topic_slug}"
LOG_FILE="$WORK_DIR/analysis/{topic_slug}/collect.log"
cd "$PLUGIN_DIR" && nohup uv run python -u scripts/collect_notes.py \
--topic-slug {topic_slug} \
--keywords "关键词1" "关键词2" ... \
--notes-per-keyword {N} \
--comments-per-note {M} \
--sort-by {sort_by} \
--work-dir "$WORK_DIR" \
> "$LOG_FILE" 2>&1 &
echo $! > "$WORK_DIR/analysis/{topic_slug}/collect.pid"
echo "后台启动,PID: $!"
启动后告知用户"爬取已在后台运行,可随时点击检查进度",然后使用 AskUserQuestion 展示等待界面:
选项:检查进度
每次用户点击"检查进度"时,执行以下检查逻辑:
# 检查是否完成
if [ -f "$WORK_DIR/analysis/{topic_slug}/raw_notes.json" ]; then
echo "DONE"
wc -c "$WORK_DIR/analysis/{topic_slug}/raw_notes.json"
else
echo "RUNNING"
tail -5 "$WORK_DIR/analysis/{topic_slug}/collect.log"
fi
DONE:告知用户爬取完成,展示笔记数量,进入 Step 3RUNNING:展示最新日志(当前进度),再次用 AskUserQuestion 展示"检查进度"选项,等待用户再次点击脚本会:
$WORK_DIR/analysis/{topic_slug}/ 创建目录RednoteMiner.crawl() 多关键词搜索,合并去重$WORK_DIR/analysis/{topic_slug}/raw_notes.json随机抽取 10 篇笔记作为样本,调用 llm_client.chat() 分析,让 LLM 提出适合该主题的结构化提取 schema。
运行 scripts/propose_schema.py:
cd "$PLUGIN_DIR" && uv run python scripts/propose_schema.py \
--topic-slug {topic_slug} \
--work-dir "$WORK_DIR"
脚本输出建议的 schema 后,获取schema内容,结构化展示给用户,询问用户是否需要修改还是确认。
用户确认的 schema 保存到 $WORK_DIR/analysis/{topic_slug}/schema.json。
Step 4 和 5 串联直接运行,无需后台:
cd "$PLUGIN_DIR" && uv run python -u scripts/extract_data.py --topic-slug {topic_slug} --work-dir "$WORK_DIR" && \
uv run python -u scripts/normalize_data.py --topic-slug {topic_slug} --work-dir "$WORK_DIR"
运行完成后直接进入 Step 6。
两个脚本分别会:
$WORK_DIR/analysis/{topic_slug}/raw_notes.json 和 schema.json,20 线程并发提取,保存为 extracted_data.jsonnormalized_data.json这一步不调用 llm_client,由 Claude 直接分析数据并撰写报告。
使用 AskUserQuestion 工具询问报告格式:
"数据处理完成,请选择报告输出格式:"
选项:Markdown(推荐)/ HTML(含可视化图表)
第一步:生成字段统计摘要
cd "$PLUGIN_DIR" && uv run python scripts/analyze_stats.py \
--topic-slug {topic_slug} \
--work-dir "$WORK_DIR"
读取 stats.md,了解每个字段的值分布和实体 note_id 索引。
第二步:按需提取数据到 Markdown(所有读入上下文的数据都用 Markdown 格式)
根据 stats.md 揭示的分布,灵活运行 to_markdown.py 提取需要的子集:
# 全量结构化摘要
cd "$PLUGIN_DIR" && uv run python scripts/to_markdown.py \
--topic-slug {topic_slug} --work-dir "$WORK_DIR"
# 按字段过滤(支持多个条件)
cd "$PLUGIN_DIR" && uv run python scripts/to_markdown.py \
--topic-slug {topic_slug} --work-dir "$WORK_DIR" \
--where sentiment=negative
cd "$PLUGIN_DIR" && uv run python scripts/to_markdown.py \
--topic-slug {topic_slug} --work-dir "$WORK_DIR" \
--where location=西湖 sentiment=positive
读取生成的 data.md,进行:
HTML 报告:使用纯 JS + CSS(无外部依赖),包含柱状图、饼图等可视化。
保存到 $WORK_DIR/analysis/{topic_slug}/report.md(或 .html),并在对话中展示摘要。
报告生成后,使用 AskUserQuestion 询问:
"报告已生成,是否需要对某个方向进行深入分析?"
选项:是,我想进一步分析 / 不需要,结束
若用户选择继续,引导用户描述想分析的方向(如"分析负面评价"、"看看提到西湖的笔记")。
下钻流程(所有读入上下文的数据均转为 Markdown):
stats.md 中的字段分布和 note_id 索引,确定过滤条件--where 过滤出目标记录的结构化摘要,读取 data.md 了解这批笔记的字段值--note-ids 提取这批笔记的原始内容(标题 + 正文 + 评论):# 步骤 2:过滤出目标记录的结构化摘要
cd "$PLUGIN_DIR" && uv run python scripts/to_markdown.py \
--topic-slug {topic_slug} --work-dir "$WORK_DIR" \
--where {过滤条件}
# 步骤 3:提取对应笔记的原始内容(从 data.md 或 stats.md 中取 note_id)
cd "$PLUGIN_DIR" && uv run python scripts/to_markdown.py \
--topic-slug {topic_slug} --work-dir "$WORK_DIR" \
--note-ids {note_id1} {note_id2} ...
notes_detail.md(原始内容)结合 data.md(结构化字段)综合分析,回答用户问题分析完成后再次展示"是否继续下钻"选项,支持多轮迭代。
npx claudepluginhub xueyouluo/rednote_mining --plugin rednote-miningBatch-scrapes Reddit discussions for a product or topic, then uses AI to annotate relevance, pros/cons, and sentiment, exporting a structured analysis report. Useful for product reputation monitoring, competitive research, and user insight gathering.
Analyzes extracted Xiaohongshu collections saved as Markdown in Obsidian vault, generating AI summaries, comparisons, step extractions for tutorials, key points for knowledge content, and theme overviews.
Orchestrates multi-agent deep research: decomposes goals into parallel sub-tasks, runs non-interactive Claude Code subprocesses with web tools, aggregates/refines into chaptered report files + summaries. Activates on 'deep research' or similar mentions, for surveys/analysis.