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

  1. Verify the ProfileTab value is one the library supports and the target account actually exposes.
  2. Dump the visible sub-tab texts on the page to compare against tabLabel mappings.
  3. Try the default TabNotes to confirm the page itself is fine.
  4. 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

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


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