xpzouying/xiaohongshu-mcp · error
通知条目渲染数(%d)少于目标位置(%d),页面可能未加载完
Error message
通知条目渲染数(%d)少于目标位置(%d),页面可能未加载完
What it means
locate() returns the index of the target comment inside the parsed payload, then Reply indexes into the rendered DOM items. If index >= len(items), the DOM rendered fewer notification entries than expected — usually because the page had not finished loading all items when the elements were queried. This is a consistency guard between API payload and DOM rendering.
Source
Thrown at xiaohongshu/notification_reply.go:46
return nil, fmt.Errorf("回复内容不能为空")
}
page := n.page.Timeout(3 * time.Minute)
page.MustNavigate("https://www.xiaohongshu.com/notification").MustWaitLoad()
humanize.Delay(ctx, humanize.AfterNavigate)
target, index, err := n.locate(ctx, page, commentID)
if err != nil {
return nil, err
}
items, err := page.Elements(`.tabs-content-container > .container`)
if err != nil {
return nil, fmt.Errorf("未找到通知条目: %w", err)
}
if index >= len(items) {
return nil, fmt.Errorf("通知条目渲染数(%d)少于目标位置(%d),页面可能未加载完", len(items), index)
}
item := items[index]
humanize.Delay(ctx, humanize.Reading)
replyBtn, err := item.Element(`.action-reply`)
if err != nil {
return nil, fmt.Errorf("该通知没有回复入口(评论可能已删除或不可回复): %w", err)
}
humanize.Delay(ctx, humanize.BeforeClick)
if err := humanize.Click(replyBtn); err != nil {
return nil, fmt.Errorf("无法点击回复: %w", err)
}
humanize.Delay(ctx, humanize.AfterClick)
input, err := item.Element(`textarea.comment-input`)
if err != nil {View on GitHub (pinned to 332d196854)
Solutions
- Retry the call — the page usually finishes rendering on a second attempt
- Slow down network or run on a faster machine/connection
- Pre-scroll the notification page before calling Reply
- Check if Xiaohongshu introduced virtualized rendering that unloads off-screen items
Defensive patterns
Strategy: retry
Try / catch
res, err := n.Reply(ctx, commentID, content)
if err != nil && strings.Contains(err.Error(), "通知条目渲染数") {
time.Sleep(3 * time.Second)
res, err = n.Reply(ctx, commentID, content)
} Prevention
- Retry on slow networks before giving up
- Avoid heavy parallel scraping on the same page
- Pre-load the notifications page before batch operations
When it happens
Trigger: Reply called when locate() found the comment at index N (possibly after scroll-loading) but the live DOM only rendered fewer than N+1 `.container` elements at query time.
Common situations: Slow network or heavy page left later items unrendered; virtualized list removed earlier items; locate() scrolled fast while DOM lagged behind.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/da480b93f5f198f2.
Report an issue: GitHub.