{"record":{"id":"35b388ed0632ec5b","repo":"xpzouying/xiaohongshu-mcp","slug":"s-w-35b388","errorCode":null,"errorMessage":"%s点击失败: %w","messagePattern":"(.+?)点击失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/like_favorite.go","lineNumber":74,"sourceCode":"}\n\nfunc (a *interactAction) performClick(page *rod.Page, selector string) error {\n\telement, err := page.Element(selector)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"未找到交互元素 %s: %w\", selector, err)\n\t}\n\treturn humanize.Click(element)\n}\n\n// stateOf 从交互状态里取目标字段（点赞取 liked，收藏取 collected）。\ntype stateOf func(liked, collected bool) bool\n\n// toggleInteract 点击交互按钮并轮询校验状态是否变为 want；最多两次点击。\n// 到达即成功；始终未变或无法读状态则返回 error——消除\"点了没报错就算成功\"的假阳性。\nfunc (a *interactAction) toggleInteract(ctx context.Context, page *rod.Page, feedID, selector string, want bool, actionType interactActionType, pick stateOf) error {\n\tfor attempt := 1; attempt <= 2; attempt++ {\n\t\tif err := a.performClick(page, selector); err != nil {\n\t\t\treturn fmt.Errorf(\"%s点击失败: %w\", actionType, err)\n\t\t}\n\n\t\tok, err := a.waitInteractState(page, feedID, want, pick, 4*time.Second)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"%s后无法确认状态: %w\", actionType, err)\n\t\t}\n\t\tif ok {\n\t\t\thumanize.Delay(ctx, humanize.AfterInteract)\n\t\t\tlogrus.Infof(\"feed %s %s成功（第%d次点击）\", feedID, actionType, attempt)\n\t\t\treturn nil\n\t\t}\n\t\tlogrus.Warnf(\"feed %s %s第%d次点击后状态未变，重试\", feedID, actionType, attempt)\n\t}\n\treturn fmt.Errorf(\"feed %s %s失败：点击后状态始终未变为预期\", feedID, actionType)\n}\n\n// waitInteractState 轮询 __INITIAL_STATE__ 的交互状态，直到 pick()==want 或超时。\n// 状态回写快则立即返回、慢则等满 timeout。","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/like_favorite.go#L56-L92","documentation":"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.","triggerScenarios":"Like or favorite action on a feed where the selector element is missing or unclickable (page not loaded, blocked note, DOM change).","commonSituations":"Rapid automation against freshly opened pages before render completes; xiaohongshu UI update; note without visible interaction bar.","solutions":["Unwrap the cause — if it's 未找到交互元素, fix the selector or add a load wait","Ensure the page is fully loaded before interacting","Check note accessibility before attempting interaction"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := client.LikeFeed(ctx, feedID)\nif err != nil && strings.Contains(err.Error(), \"点击失败\") {\n    time.Sleep(2 * time.Second)\n    err = client.LikeFeed(ctx, feedID) // one manual retry after load settle\n}","preventionTips":["Allow the detail page to fully render before clicking","Unwrap the cause: element-not-found vs click error need different fixes","Throttle interactions to avoid anti-bot suppression of buttons"],"tags":["interaction","click","scraping"],"backgroundTag":"element-not-found","analyzedSha":"332d196854a9eac0d2b8c2c0e3d0cc43139d724c","analyzedAt":"2026-09-05T22:22:55.988Z","contentChangedAt":"2026-09-05T22:22:55.988Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}