xpzouying/xiaohongshu-mcp · error

通知条目渲染数(%d)少于目标位置(%d),页面可能未加载完

Error message

通知条目渲染数(%d)少于目标位置(%d),页面可能未加载完

What it means

Like 已知目标通知在数据列表中的位置 index,但渲染出的 .container 条目数量不大于 index:页面还没渲染完足够的条目(懒加载/渲染延迟),定位不到要点击的那条通知。

Source

Thrown at xiaohongshu/notification_like.go:60

	result := &NotificationLikeResult{
		CommentID: commentID,
		Nickname:  target.from().Nickname,
		Liked:     want,
	}

	if target.Comment.Liked == want {
		result.Skipped = true
		logrus.Infof("通知点赞跳过(已是目标状态): comment=%s liked=%v", commentID, want)
		return result, nil
	}

	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)
	}

	humanize.Delay(ctx, humanize.Reading)

	btn, err := items[index].Element(`.action-like .like-wrapper`)
	if err != nil {
		return nil, fmt.Errorf("该通知没有点赞入口(评论可能已删除或不可点赞): %w", err)
	}

	humanize.Delay(ctx, humanize.BeforeClick)
	if err := humanize.Click(btn); err != nil {
		return nil, fmt.Errorf("无法点击点赞: %w", err)
	}

	if err := n.waitLikeSettled(page, commentID, want); err != nil {
		return nil, err
	}

View on GitHub (pinned to 332d196854)

Solutions

  1. 先用 list_notifications 刷新通知列表,确认目标 commentID 仍在列表内
  2. 在页面内滚动触发懒加载后再获取元素
  3. 若通知已不在列表,走备选路径(直接通过评论接口操作)
  4. 重试一次,因为列表顺序是动态变化的

Example fix

// before
if index >= len(items) { return nil, fmt.Errorf("通知条目渲染数(%d)少于目标位置(%d)...", len(items), index) }
// after
for index >= len(items) && attempts < 3 {
    humanize.ScrollDown(page)
    items, err = page.Elements(`.tabs-content-container > .container`)
    attempts++
}
if index >= len(items) { return nil, fmt.Errorf("通知条目渲染数(%d)少于目标位置(%d)...", len(items), index) }
Defensive patterns

Strategy: retry

Validate before calling

// 先确认目标通知仍在列表前几屏
items, _ := n.List(ctx)
found := false
for _, it := range items { if it.CommentID == commentID { found = true; break } }
if !found { return errors.New("notification not in first page") }

Try / catch

_, err := n.Like(ctx, commentID, false)
if err != nil && strings.Contains(err.Error(), "少于目标位置") {
    // 刷新列表后重试;仍失败则改走直接评论接口
    _, err = n.Like(ctx, commentID, false)
}

Prevention

When it happens

Trigger: Like 内部 locate 得到的 index >= len(items):目标评论在通知列表较深位置但页面只渲染了第一屏;通知已被刷出列表;分页/懒加载未触发。

Common situations: 目标评论的通知太久远被更新的通知挤掉;通知列表很短而 index 由历史数据计算;页面懒加载没滚到底。

Related errors


AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05). Data as JSON: /api/errors/84e01e81ad85c74d. Report an issue: GitHub.