diff --git a/clis/xiaohongshu/note.test.ts b/clis/xiaohongshu/note.test.ts index cfa07abe2..5e752859f 100644 --- a/clis/xiaohongshu/note.test.ts +++ b/clis/xiaohongshu/note.test.ts @@ -199,6 +199,20 @@ describe('xiaohongshu note', () => { expect(result.find((r: any) => r.field === 'comments')!.value).toBe('0'); }); + it('scopes metric selectors to .interact-container to avoid matching comment like buttons', async () => { + const page = createPageMock({ + loginWall: false, notFound: false, + title: 'Test', desc: '', author: 'Author', likes: '10', collects: '5', comments: '3', tags: [], + }); + + await command!.func!(page, { 'note-id': 'abc123' }); + + const evaluateScript: string = (page.evaluate as any).mock.calls[0][0]; + expect(evaluateScript).toContain('.interact-container .like-wrapper .count'); + expect(evaluateScript).toContain('.interact-container .collect-wrapper .count'); + expect(evaluateScript).toContain('.interact-container .chat-wrapper .count'); + }); + it('omits tags row when no tags present', async () => { const page = createPageMock({ loginWall: false, notFound: false, diff --git a/clis/xiaohongshu/note.ts b/clis/xiaohongshu/note.ts index 6315618d3..1d2adf81f 100644 --- a/clis/xiaohongshu/note.ts +++ b/clis/xiaohongshu/note.ts @@ -41,9 +41,14 @@ cli({ const title = clean(document.querySelector('#detail-title, .title')) const desc = clean(document.querySelector('#detail-desc, .desc, .note-text')) const author = clean(document.querySelector('.username, .author-wrapper .name')) - const likes = clean(document.querySelector('.like-wrapper .count')) - const collects = clean(document.querySelector('.collect-wrapper .count')) - const comments = clean(document.querySelector('.chat-wrapper .count')) + // Scope to .interact-container — the post's main interaction bar. + // Without scoping, .like-wrapper / .chat-wrapper also match each + // comment's like/reply buttons in the comment section, and + // querySelector returns the FIRST match (a comment's count, not the + // post's). The post's true counts live inside .interact-container. + const likes = clean(document.querySelector('.interact-container .like-wrapper .count')) + const collects = clean(document.querySelector('.interact-container .collect-wrapper .count')) + const comments = clean(document.querySelector('.interact-container .chat-wrapper .count')) // Try to extract tags/topics const tags = []