灵猴市集Linghou Market

小红书笔记提取

小红书xhs-note-extract

用途 提取当前小红书笔记详情页的标题、作者、正文、点赞数、收藏数、评论数和话题标签。 执行前提 先在浏览器中打开一篇小红书笔记详情页。 支持 xiaohongshu.com 和 rednote.com 页面。 如果页面要求登录、笔记不存在或触发安全限制,脚本会返回明确错误。 参数 不需要参数。脚本直接读取当前标签页里的笔记内容。 示例

笔记内容提取
版本1.0.0
扫描passed
更新2026-06-28
超时30000ms

匹配范围

*://*.xiaohongshu.com/**://*.rednote.com/*

排除范围

未声明

能力声明

dom.read

代码

源码已展开
1if (!/(^|\.)xiaohongshu\.com$/i.test(location.hostname) && !/(^|\.)rednote\.com$/i.test(location.hostname)) {2  throw new Error('请先在小红书笔记详情页执行该脚本');3}4 5const bodyText = document.body?.innerText || '';6const loginWall = /登录后查看|请登录/.test(bodyText);7const notFound = /页面不见了|笔记不存在|无法浏览/.test(bodyText);8const securityBlock = /安全限制|访问链接异常/.test(bodyText)9  || /website-login\/error|error_code=300017|error_code=300031/.test(location.href);10 11const clean = (el) => (el?.textContent || '').replace(/\s+/g, ' ').trim();12const title = clean(document.querySelector('#detail-title, .title'));13const content = clean(document.querySelector('#detail-desc, .desc, .note-text'));14const author = clean(document.querySelector('.username, .author-wrapper .name'));15const likes = clean(document.querySelector('.interact-container .like-wrapper .count'));16const collects = clean(document.querySelector('.interact-container .collect-wrapper .count'));17const comments = clean(document.querySelector('.interact-container .chat-wrapper .count'));18const tags = [];19 20document.querySelectorAll('#detail-desc a.tag, #detail-desc a[href*="search_result"]').forEach((el) => {21  const text = (el.textContent || '').trim();22  if (text) tags.push(text);23});24 25if (securityBlock) throw new Error('小红书安全限制或风控页面');26if (loginWall) throw new Error('当前笔记需要登录后查看');27if (notFound) throw new Error('笔记不存在、已删除或不可浏览');28if (!title && !author) throw new Error('页面没有可提取的笔记内容');29 30const normalizeCount = (value) => /^\d+/.test(value) ? value : '0';31return {32  pageUrl: location.href,33  title,34  author,35  content,36  likes: normalizeCount(likes),37  collects: normalizeCount(collects),38  comments: normalizeCount(comments),39  tags,40};