xpzouying/xiaohongshu-mcp · error
user.userPageData.value not found in __INITIAL_STATE__
Error message
user.userPageData.value not found in __INITIAL_STATE__
What it means
extractUserProfileData 执行 JS 提取 window.__INITIAL_STATE__.user.userPageData(兼容 value/_value 解包)后返回空串:页面未注水用户资料数据——用户不存在、未登录或前端状态结构变化。
Source
Thrown at xiaohongshu/user_profile.go:81
// extractUserProfileData 从页面中提取用户资料数据的通用方法
func (u *UserProfileAction) extractUserProfileData(page *rod.Page, tab ProfileTab) (*UserProfileResponse, error) {
page.MustWait(`() => window.__INITIAL_STATE__ !== undefined`)
userDataResult := page.MustEval(`() => {
if (window.__INITIAL_STATE__ &&
window.__INITIAL_STATE__.user &&
window.__INITIAL_STATE__.user.userPageData) {
const userPageData = window.__INITIAL_STATE__.user.userPageData;
const data = userPageData.value !== undefined ? userPageData.value : userPageData._value;
if (data) {
return JSON.stringify(data);
}
}
return "";
}`).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__")
}
// 解析用户信息View on GitHub (pinned to 332d196854)
Solutions
- 在调用前等待页面水合完成(等待用户头像/昵称等元素出现)
- 确认已登录且目标主页可正常访问(浏览器手动打开验证)
- 升级库版本适配最新的 state 结构
- 加重试:偶发的渲染时序问题通常重试即可
Example fix
// before
res, err := client.UserProfile(ctx, userID, "note")
// after
page.MustWait("div.user-info, .nickname") // 等水合
res, err := client.UserProfile(ctx, userID, "note")
if err != nil && strings.Contains(err.Error(), "not found in __INITIAL_STATE__") {
time.Sleep(2 * time.Second)
res, err = client.UserProfile(ctx, userID, "note")
} Defensive patterns
Strategy: retry
Validate before calling
// 调用前确认用户主页可访问(HTTP 探测或手动验证)
if !userProfileReachable(userID) {
return errors.New("用户主页不可访问,可能需要登录或用户不存在")
} Try / catch
res, err := client.UserProfile(ctx, userID, tab)
if err != nil && strings.Contains(err.Error(), "not found in __INITIAL_STATE__") {
time.Sleep(2 * time.Second) // 等水合
res, err = client.UserProfile(ctx, userID, tab)
}
if err != nil { return err } Prevention
- 确保处于有效登录态
- 访问前确认目标用户主页正常存在
- 对渲染时序问题做有限次重试
- 升级库版本适配 __INITIAL_STATE__ 结构变更
- 注意风控/验证码页会导致 state 缺失
When it happens
Trigger: 调用 UserProfile 或 GetMyProfileViaSidebar 时,目标页面的 __INITIAL_STATE__ 尚未注入、user.userPageData 节点不存在或 value 为空——典型于页面未完成水合、被重定向到登录页、或用户主页不存在/被封。
Common situations: 未登录访问受限主页;小红书改版移动了 __INITIAL_STATE__ 的数据路径;页面加载过慢,在 state 注入前就执行了 Eval;触发了风控验证码页。
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/fb0ce16da2434b9b.
Report an issue: GitHub.