xpzouying/xiaohongshu-mcp · error

%s点击失败: %w

Error message

%s点击失败: %w

What it means

toggleInteract wraps performClick failures as '<actionType>点击失败: %w' (e.g. '点赞点击失败'). It means the click on the like/favorite button could not be performed, usually because the element was never found.

Source

Thrown at xiaohongshu/like_favorite.go:74

}

func (a *interactAction) performClick(page *rod.Page, selector string) error {
	element, err := page.Element(selector)
	if err != nil {
		return fmt.Errorf("未找到交互元素 %s: %w", selector, err)
	}
	return humanize.Click(element)
}

// stateOf 从交互状态里取目标字段(点赞取 liked,收藏取 collected)。
type stateOf func(liked, collected bool) bool

// toggleInteract 点击交互按钮并轮询校验状态是否变为 want;最多两次点击。
// 到达即成功;始终未变或无法读状态则返回 error——消除"点了没报错就算成功"的假阳性。
func (a *interactAction) toggleInteract(ctx context.Context, page *rod.Page, feedID, selector string, want bool, actionType interactActionType, pick stateOf) error {
	for attempt := 1; attempt <= 2; attempt++ {
		if err := a.performClick(page, selector); err != nil {
			return fmt.Errorf("%s点击失败: %w", actionType, err)
		}

		ok, err := a.waitInteractState(page, feedID, want, pick, 4*time.Second)
		if err != nil {
			return fmt.Errorf("%s后无法确认状态: %w", actionType, err)
		}
		if ok {
			humanize.Delay(ctx, humanize.AfterInteract)
			logrus.Infof("feed %s %s成功(第%d次点击)", feedID, actionType, attempt)
			return nil
		}
		logrus.Warnf("feed %s %s第%d次点击后状态未变,重试", feedID, actionType, attempt)
	}
	return fmt.Errorf("feed %s %s失败:点击后状态始终未变为预期", feedID, actionType)
}

// waitInteractState 轮询 __INITIAL_STATE__ 的交互状态,直到 pick()==want 或超时。
// 状态回写快则立即返回、慢则等满 timeout。

View on GitHub (pinned to 332d196854)

Solutions

  1. Unwrap the cause — if it's 未找到交互元素, fix the selector or add a load wait
  2. Ensure the page is fully loaded before interacting
  3. Check note accessibility before attempting interaction
Defensive patterns

Strategy: retry

Try / catch

err := client.LikeFeed(ctx, feedID)
if err != nil && strings.Contains(err.Error(), "点击失败") {
    time.Sleep(2 * time.Second)
    err = client.LikeFeed(ctx, feedID) // one manual retry after load settle
}

Prevention

When it happens

Trigger: Like or favorite action on a feed where the selector element is missing or unclickable (page not loaded, blocked note, DOM change).

Common situations: Rapid automation against freshly opened pages before render completes; xiaohongshu UI update; note without visible interaction bar.

Related errors


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