xpzouying/xiaohongshu-mcp · error
未找到子 tab %q
Error message
未找到子 tab %q
What it means
selectTab enumerated all `.reds-tab-item.sub-tab-list` elements and none matched the requested tab label (xiaohongshu/user_profile.go:194). This is a plain (non-wrapped) error with the label in %q, meaning the sub-tab list rendered but the desired tab is absent. Note: elem.Text() errors are silently skipped, so a read failure also surfaces as 'not found'.
Source
Thrown at xiaohongshu/user_profile.go:194
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
- Verify the ProfileTab value is one the library supports and the target account actually exposes.
- Dump the visible sub-tab texts on the page to compare against tabLabel mappings.
- Try the default TabNotes to confirm the page itself is fine.
- If XHS changed tab wording, update the tabLabel map in the library.
Example fix
// before
resp, err := action.GetMyProfileViaSidebar(ctx, xiaohongshu.TabLike)
// after
if !accountExposesTab(profile, xiaohongshu.TabLike) {
resp, err = action.GetMyProfileViaSidebar(ctx, xiaohongshu.TabNotes)
} else {
resp, err = action.GetMyProfileViaSidebar(ctx, xiaohongshu.TabLike)
} Defensive patterns
Strategy: validation
Validate before calling
var tab ProfileTab = tabFlag // validate against supported set first
switch tab {
case "", TabNotes, TabLike, TabCollect:
default:
return fmt.Errorf("unsupported tab %q", tab)
} Try / catch
resp, err := action.GetMyProfileViaSidebar(ctx, tab)
if err != nil && strings.HasPrefix(err.Error(), "未找到子 tab") {
log.Printf("account does not expose tab %s, falling back to notes", tab)
resp, err = action.GetMyProfileViaSidebar(ctx, TabNotes)
} Prevention
- Only request tabs the target account actually exposes.
- Use library-defined ProfileTab constants, never free-form strings.
- Fall back to the default TabNotes when a tab is absent.
- Update tabLabel mappings when XHS renames tab text.
When it happens
Trigger: Calling GetMyProfileViaSidebar(ctx, tab) with a tab whose label (tabLabel[tab]) doesn't exist on the page — the account has no such sub-tab (e.g. empty 收藏), or the requested ProfileTab value has no mapping in tabLabel so the label is empty and never matches.
Common situations: Requesting a tab the account doesn't expose (private likes, empty collections); passing an unsupported/typo ProfileTab value; XHS renaming tab text so the label comparison fails; text read errors being swallowed by `continue`.
Related errors
- 未找到主页子 tab: %w
- 未找到评论 %s,它可能不在「评论和@」里或已被清理
- 回复未确认成功:发送后输入框仍未收起(可能被限制或发送失败)
- failed to navigate to profile page via sidebar: %w
- 切换到 %s 失败: %w
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/7f04cf5f219ec2a0.
Report an issue: GitHub.