rednote-mcp
Version:
A friendly tool to help you access and interact with Xiaohongshu (RedNote) content through Model Context Protocol.
66 lines (65 loc) • 3.03 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GetNoteDetail = GetNoteDetail;
const logger_1 = __importDefault(require("../utils/logger"));
async function GetNoteDetail(page) {
// Wait for content to load
logger_1.default.info('Waiting for content to load');
await page.waitForSelector('.note-container');
await page.waitForSelector('.media-container');
async function getContent() {
function ChineseUnitStrToNumber(str) {
if (str.includes('万')) {
return Number(str.replace('万', '').trim()) * 10000;
}
else {
return Number(str);
}
}
// Get main article content
const article = document.querySelector('.note-container');
if (!article)
throw new Error('Article not found');
// Get title from h1 or first text block
const title = article.querySelector('#detail-title')?.textContent?.trim() ||
article.querySelector('.title')?.textContent?.trim() ||
'';
// Get content from article text
const contentBlock = article.querySelector('.note-scroller');
if (!contentBlock)
throw new Error('Content block not found');
const content = contentBlock.querySelector('.note-content .note-text span')?.textContent?.trim() || '';
// Get tags from article text
const tags = Array.from(contentBlock?.querySelectorAll('.note-content .note-text a')).map((tag) => {
return tag.textContent?.trim().replace('#', '') || '';
});
// Get author info
const authorElement = article.querySelector('.author-container .info');
const authorAvatarURL = authorElement?.querySelector('.avatar-item')?.getAttribute('src') || '';
const author = authorElement?.querySelector('.username')?.textContent?.trim() || '';
const interactContainer = document.querySelector('.interact-container');
const commentsNumber = interactContainer?.querySelector('.chat-wrapper .count')?.textContent?.trim() || '';
const likesNumber = interactContainer?.querySelector('.like-wrapper .count')?.textContent?.trim() || '';
const imgs = Array.from(document.querySelectorAll('.media-container img')).map((img) => {
return img.getAttribute('src') || '';
});
const videos = Array.from(document.querySelectorAll('.media-container video')).map((video) => {
return video.getAttribute('src') || '';
});
return {
title,
content,
tags,
author,
imgs,
videos,
url: '',
likes: ChineseUnitStrToNumber(likesNumber),
comments: ChineseUnitStrToNumber(commentsNumber)
};
}
return await page.evaluate(getContent);
}