xpzouying/xiaohongshu-mcp · error
user.notes.value not found in __INITIAL_STATE__
Error message
user.notes.value not found in __INITIAL_STATE__
What it means
extractUserProfileData 提取 user.notes(及 activeTab)时 JS 返回空串:__INITIAL_STATE__.user.notes 不存在或解包后为空,笔记列表未注入——tab 未加载完成或结构变化。
Source
Thrown at xiaohongshu/user_profile.go:96
}`).String()
if userDataResult == "" {
return nil, fmt.Errorf("user.userPageData.value not found in __INITIAL_STATE__")
}
// 2. 获取用户帖子及当前 tab:window.__INITIAL_STATE__.user
notesResult := page.MustEval(`() => {
const u = window.__INITIAL_STATE__ && window.__INITIAL_STATE__.user;
if (!u || !u.notes) return "";
const unwrap = (o) => (o && o.value !== undefined) ? o.value : (o && o._value);
const notes = unwrap(u.notes);
if (!notes) return "";
const active = unwrap(u.activeTab) || {};
return JSON.stringify({notes: notes, index: active.index || 0, query: active.query || ""});
}`).String()
if notesResult == "" {
return nil, fmt.Errorf("user.notes.value not found in __INITIAL_STATE__")
}
// 解析用户信息
var userPageData struct {
Interactions []UserInteractions `json:"interactions"`
BasicInfo UserBasicInfo `json:"basicInfo"`
}
if err := json.Unmarshal([]byte(userDataResult), &userPageData); err != nil {
return nil, fmt.Errorf("failed to unmarshal userPageData: %w", err)
}
var notesData struct {
Notes [][]Feed `json:"notes"`
Index int `json:"index"`
Query string `json:"query"`
}
if err := json.Unmarshal([]byte(notesResult), ¬esData); err != nil {
return nil, fmt.Errorf("failed to unmarshal notes: %w", err)View on GitHub (pinned to 332d196854)
Solutions
- 确认目标用户确实有笔记,或接受空结果的处理逻辑
- 确认当前 tab(收藏/点赞)在登录态下可见
- 调用前等待笔记列表容器渲染完成
- 升级库版本适配最新 state 结构
Example fix
// before
res, err := client.UserProfile(ctx, userID, "fav") // 未登录时 fav 无数据
// after
if !client.LoggedIn() { return errors.New("收藏/点赞 tab 需要登录态") }
res, err = client.UserProfile(ctx, userID, "fav") Defensive patterns
Strategy: fallback
Validate before calling
if !client.LoggedIn() {
return errors.New("收藏/点赞等受限 tab 需要登录态")
} Try / catch
res, err := client.UserProfile(ctx, userID, tab)
if err != nil && strings.Contains(err.Error(), "user.notes.value not found") {
// 该用户可能无笔记或受限,返回空结果而非失败
return &xiaohongshu.UserProfileResponse{}, nil
} Prevention
- 区分「无数据」与「加载失败」,零笔记用户可回退空结果
- 受限 tab 需保持登录态
- 升级库版本适配 state 路径变更
- 对慢加载页面先等待笔记容器渲染
When it happens
Trigger: 调用 UserProfile / GetMyProfileViaSidebar 时,__INITIAL_STATE__.user.notes 节点不存在或 value 为空——常见于该用户笔记数为 0、目标 tab 数据未加载、页面被重定向或水合未完成。
Common situations: 访问零笔记的新账号;收藏/点赞 tab 未登录不可见导致 notes 为空;改版后数据路径变化;页面慢导致提前 Eval。
Related errors
- user.userPageData.value not found in __INITIAL_STATE__
- 读取筛选面板失败: %w
- 读取「%s」的选项失败: %w
- ErrNoFeeds
- ErrNoFeedDetail
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/a4a1a2597604e141.
Report an issue: GitHub.