xpzouying/xiaohongshu-mcp · error

未找到通知条目: %w

Error message

未找到通知条目: %w

What it means

Like 在通知页用 .tabs-content-container > .container 查找通知条目 DOM 时 page.Elements 报错:通知列表未渲染或页面结构变化。与渲染数不足的分支不同,这里是查询本身失败。

Source

Thrown at xiaohongshu/notification_like.go:57

	if err != nil {
		return nil, err
	}

	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 {

View on GitHub (pinned to 332d196854)

Solutions

  1. 确认登录态有效(Cookie 未过期,能正常打开通知页)
  2. 手动检查通知页 DOM,确认 .tabs-content-container > .container 选择器仍然有效
  3. 在 Elements 查询前增加 WaitLoad/WaitVisible 等待页面就绪
  4. 改版时更新 notification_like.go 中的选择器常量

Example fix

// before
items, err := page.Elements(`.tabs-content-container > .container`)
// after
page.MustWaitLoad()
_ = page.WaitVisible(`.tabs-content-container > .container`, rod.WaitMax(30*time.Second))
items, err := page.Elements(`.tabs-content-container > .container`)
Defensive patterns

Strategy: retry

Validate before calling

// 调用前确认页面停留在通知页
url := page.MustInfo().URL
if !strings.HasPrefix(url, "https://www.xiaohongshu.com/notification") { return errors.New("not on notification page: " + url) }

Try / catch

_, err := n.Like(ctx, commentID, false)
if err != nil && strings.Contains(err.Error(), "未找到通知条目") {
    time.Sleep(2 * time.Second) // 等页面就绪后重试一次
    _, err = n.Like(ctx, commentID, false)
}

Prevention

When it happens

Trigger: locate 算出的 index 对应页面无 .tabs-content-container > .container 元素:未登录跳转、通知页结构改版、页面加载失败后仍执行查询。

Common situations: Cookie 失效被重定向到登录页;小红书前端改类名;页面加载中断(网络错误/验证码页)。

Related errors


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