{"record":{"id":"a4a1a2597604e141","repo":"xpzouying/xiaohongshu-mcp","slug":"user-notes-value-not-found-in-initial-state","errorCode":null,"errorMessage":"user.notes.value not found in __INITIAL_STATE__","messagePattern":"user\\.notes\\.value not found in __INITIAL_STATE__","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/user_profile.go","lineNumber":96,"sourceCode":"\t}`).String()\n\n\tif userDataResult == \"\" {\n\t\treturn nil, fmt.Errorf(\"user.userPageData.value not found in __INITIAL_STATE__\")\n\t}\n\n\t// 2. 获取用户帖子及当前 tab：window.__INITIAL_STATE__.user\n\tnotesResult := page.MustEval(`() => {\n\t\tconst u = window.__INITIAL_STATE__ && window.__INITIAL_STATE__.user;\n\t\tif (!u || !u.notes) return \"\";\n\t\tconst unwrap = (o) => (o && o.value !== undefined) ? o.value : (o && o._value);\n\t\tconst notes = unwrap(u.notes);\n\t\tif (!notes) return \"\";\n\t\tconst active = unwrap(u.activeTab) || {};\n\t\treturn JSON.stringify({notes: notes, index: active.index || 0, query: active.query || \"\"});\n\t}`).String()\n\n\tif notesResult == \"\" {\n\t\treturn nil, fmt.Errorf(\"user.notes.value not found in __INITIAL_STATE__\")\n\t}\n\n\t// 解析用户信息\n\tvar userPageData struct {\n\t\tInteractions []UserInteractions `json:\"interactions\"`\n\t\tBasicInfo    UserBasicInfo      `json:\"basicInfo\"`\n\t}\n\tif err := json.Unmarshal([]byte(userDataResult), &userPageData); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal userPageData: %w\", err)\n\t}\n\n\tvar notesData struct {\n\t\tNotes [][]Feed `json:\"notes\"`\n\t\tIndex int      `json:\"index\"`\n\t\tQuery string   `json:\"query\"`\n\t}\n\tif err := json.Unmarshal([]byte(notesResult), &notesData); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to unmarshal notes: %w\", err)","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/user_profile.go#L78-L114","documentation":"extractUserProfileData 提取 user.notes（及 activeTab）时 JS 返回空串：__INITIAL_STATE__.user.notes 不存在或解包后为空，笔记列表未注入——tab 未加载完成或结构变化。","triggerScenarios":"调用 UserProfile / GetMyProfileViaSidebar 时，__INITIAL_STATE__.user.notes 节点不存在或 value 为空——常见于该用户笔记数为 0、目标 tab 数据未加载、页面被重定向或水合未完成。","commonSituations":"访问零笔记的新账号；收藏/点赞 tab 未登录不可见导致 notes 为空；改版后数据路径变化；页面慢导致提前 Eval。","solutions":["确认目标用户确实有笔记，或接受空结果的处理逻辑","确认当前 tab（收藏/点赞）在登录态下可见","调用前等待笔记列表容器渲染完成","升级库版本适配最新 state 结构"],"exampleFix":"// before\nres, err := client.UserProfile(ctx, userID, \"fav\") // 未登录时 fav 无数据\n// after\nif !client.LoggedIn() { return errors.New(\"收藏/点赞 tab 需要登录态\") }\nres, err = client.UserProfile(ctx, userID, \"fav\")","handlingStrategy":"fallback","validationCode":"if !client.LoggedIn() {\n    return errors.New(\"收藏/点赞等受限 tab 需要登录态\")\n}","typeGuard":null,"tryCatchPattern":"res, err := client.UserProfile(ctx, userID, tab)\nif err != nil && strings.Contains(err.Error(), \"user.notes.value not found\") {\n    // 该用户可能无笔记或受限，返回空结果而非失败\n    return &xiaohongshu.UserProfileResponse{}, nil\n}","preventionTips":["区分「无数据」与「加载失败」，零笔记用户可回退空结果","受限 tab 需保持登录态","升级库版本适配 state 路径变更","对慢加载页面先等待笔记容器渲染"],"tags":["scraping","initial-state","hydration","go-rod"],"backgroundTag":"initial-state-missing","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"}