Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions clis/xiaohongshu/note.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 8 additions & 3 deletions clis/xiaohongshu/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down