xpzouying/xiaohongshu-mcp · error
查找原创声明卡片失败
Error message
查找原创声明卡片失败
What it means
Thrown by setOriginal when page.Elements("div.custom-switch-card") fails to list the settings cards, meaning no div.custom-switch-card existed on the page — the publish settings section did not render or its markup changed.
Source
Thrown at xiaohongshu/publish.go:981
}
if err := humanize.Type(ctx, elem, dateTimeStr); err != nil {
return errors.Wrap(err, "输入日期时间失败")
}
slog.Info("已设置日期时间", "datetime", dateTimeStr)
return nil
}
// setOriginal 设置原创声明
func setOriginal(page *rod.Page) error {
// 根据小红书创作者页面的实际结构:
// div.custom-switch-card 包含 span.has-tips 文本为"原创声明"
// 开关是 div.d-switch 组件
// 查找包含"原创声明"文本的 custom-switch-card
switchCards, err := page.Elements("div.custom-switch-card")
if err != nil {
return errors.Wrap(err, "查找原创声明卡片失败")
}
for _, card := range switchCards {
text, err := card.Text()
if err != nil {
continue
}
// 检查是否是原创声明卡片
if !strings.Contains(text, "原创声明") {
continue
}
// 找到原创声明卡片,查找其中的 d-switch
switchElem, err := card.Element("div.d-switch")
if err != nil {
continue
}View on GitHub (pinned to 332d196854)
Solutions
- Wait for the settings section to render before setOriginal (Wait on div.custom-switch-card).
- Dump page.HTML() on failure and update the selector if the class name changed.
- Ensure prior publish steps (media upload, title) completed so the settings panel exists.
- Increase the Elements timeout on slow networks.
Example fix
// before
switchCards, err := page.Elements("div.custom-switch-card")
// after
if err := page.Wait("() => !!document.querySelector('div.custom-switch-card')"); err != nil {
return errors.Wrap(err, "发布设置面板未渲染")
}
switchCards, err := page.Elements("div.custom-switch-card") Defensive patterns
Strategy: validation
Validate before calling
if err := page.Wait("() => !!document.querySelector('div.custom-switch-card')"); err != nil {
return fmt.Errorf("发布设置面板未渲染: %w", err)
} Try / catch
if err := setOriginal(page); err != nil {
if strings.Contains(err.Error(), "查找原创声明卡片失败") {
html, _ := page.HTML()
slog.Warn("switch cards missing", "htmlLen", len(html))
}
return err
} Prevention
- Ensure media upload and prior steps completed before touching the settings panel.
- Wait for the settings cards to exist instead of fixed sleeps.
- Update selectors promptly when XHS ships front-end changes; track with a selector-verification test.
- Handle late-appearing panels on slow networks with longer waits.
When it happens
Trigger: Calling submitPublish before the settings panel rendered; XHS renamed custom-switch-card after a front-end update; the page is on the wrong step of the publish wizard.
Common situations: XHS A/B redesign; the publish page still uploading media so settings cards appear late; an earlier automation step failed silently leaving the flow on a different panel.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/824f82ead9274dbc.
Report an issue: GitHub.