xpzouying/xiaohongshu-mcp · error

未找到主页子 tab: %w

Error message

未找到主页子 tab: %w

What it means

selectTab fails while querying the profile page's sub-tab elements via the CSS selector `.reds-tab-item.sub-tab-list` (xiaohongshu/user_profile.go:178). This error means the rod call to enumerate sub-tab elements itself errored (element lookup/eval failure), not that matching tabs are absent. GetMyProfileViaSidebar propagates it unchanged.

Source

Thrown at xiaohongshu/user_profile.go:178

	page.MustWaitStable()

	if err := u.selectTab(ctx, page, tab); err != nil {
		return nil, err
	}

	return u.extractUserProfileData(page, tab)
}

// selectTab 切到目标子 tab。「笔记」是默认 tab,无需点击。
func (u *UserProfileAction) selectTab(ctx context.Context, page *rod.Page, tab ProfileTab) error {
	if tab == "" || tab == TabNotes {
		return nil
	}

	label := tabLabel[tab]
	elems, err := page.Elements(`.reds-tab-item.sub-tab-list`)
	if err != nil {
		return fmt.Errorf("未找到主页子 tab: %w", err)
	}

	for _, elem := range elems {
		text, err := elem.Text()
		if err != nil || strings.TrimSpace(text) != label {
			continue
		}
		humanize.Delay(ctx, humanize.BeforeClick)
		if err := humanize.Click(elem); err != nil {
			return fmt.Errorf("切换到 %s 失败: %w", label, err)
		}
		humanize.Delay(ctx, humanize.AfterClick)
		page.MustWaitStable()
		return nil
	}
	return fmt.Errorf("未找到子 tab %q", label)
}

View on GitHub (pinned to 332d196854)

Solutions

  1. Check the wrapped rod error — if it indicates no element, the page likely never rendered the tab bar; verify login state.
  2. Re-navigate and retry after MustWaitStable.
  3. If XHS renamed the sub-tab classes, update the `.reds-tab-item.sub-tab-list` selector.
Defensive patterns

Strategy: try-catch

Try / catch

resp, err := action.GetMyProfileViaSidebar(ctx, tab)
if err != nil && strings.Contains(err.Error(), "未找到主页子 tab") {
    // page never rendered the tab bar — re-navigate or check login
    return reLoginAndRetry(ctx)
}

Prevention

When it happens

Trigger: Calling GetMyProfileViaSidebar with a non-default tab (e.g. TabCollect/TabLike) when page.Elements(`.reds-tab-item.sub-tab-list`) returns a rod error — page navigated away, JS context destroyed, or page closed.

Common situations: Profile page redirected to a login wall so the sub-tab bar never rendered; page crashed mid-navigation; browser disconnected.

Related errors


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