import { chromium } from 'rebrowser-playwright'; import { readFileSync } from 'node:fs'; const COOKIE_FILE = `${process.env.HOME}/.social-mcp/xiaohongshu/cookies.json`; const userId = '5b29b622e8ac2b5a12ae97fc'; const xsecToken = 'ABrhIpSL55O66wuekMtlJUxsX4EpaNTlfCYwDo6UfKrrM='; async function main() { const raw = JSON.parse(readFileSync(COOKIE_FILE, 'utf-8')); const browser = await chromium.launch({ headless: true, args: ['--no-sandbox','--disable-setuid-sandbox','--disable-dev-shm-usage','--disable-gpu'] }); const ctx = await browser.newContext({ storageState: raw }); const page = await ctx.newPage(); // Warm up: visit explore first console.log('Warming up: visiting explore...'); await page.goto('https://www.xiaohongshu.com/explore', { waitUntil: 'domcontentloaded' }); await page.waitForTimeout(2000); console.log('Explore title:', await page.title()); // Now try profile with pc_feed source (matching the token's source) const url = `https://www.xiaohongshu.com/user/profile/${userId}?xsec_token=${encodeURIComponent(xsecToken)}&xsec_source=pc_feed`; console.log('\nNavigating to profile (xsec_source=pc_feed)...'); await page.goto(url, { waitUntil: 'domcontentloaded' }); await page.waitForTimeout(2000); console.log('title:', await page.title()); console.log('url:', page.url().slice(0, 80)); const nickname = await page.$eval('.user-info .user-name', el => el.textContent?.trim() ?? '').catch(() => 'NOT FOUND'); console.log('nickname:', nickname); const feeds = await page.$$('.feeds-container .note-item'); console.log('note items:', feeds.length); if (feeds.length > 0) { const href = await feeds[0]!.$eval('a.cover', el => el.getAttribute('href') ?? '').catch(() => ''); console.log('first note href:', href); } await browser.close(); } main().catch(e => { console.error(e); process.exit(1); });