xpzouying/xiaohongshu-mcp · error
未找到评论输入区域: %w
Error message
未找到评论输入区域: %w
What it means
After clicking, PostComment waits for the actual text input 'div.input-box div.content-edit p.content-input' to appear. If this element is missing, the editor did not open as expected and this wrapped error is returned.
Source
Thrown at xiaohongshu/comment_feed.go:56
return err
}
elem, err := page.Element("div.input-box div.content-edit span")
if err != nil {
logrus.Warnf("Failed to find comment input box: %v", err)
return fmt.Errorf("未找到评论输入框,该帖子可能不支持评论或网页端不可访问: %w", err)
}
if err := humanize.Click(elem); err != nil {
logrus.Warnf("Failed to click comment input box: %v", err)
return fmt.Errorf("无法点击评论输入框: %w", err)
}
humanize.Delay(ctx, humanize.AfterClick)
elem2, err := page.Element("div.input-box div.content-edit p.content-input")
if err != nil {
logrus.Warnf("Failed to find comment input field: %v", err)
return fmt.Errorf("未找到评论输入区域: %w", err)
}
if err := humanize.Type(ctx, elem2, content); err != nil {
logrus.Warnf("Failed to input comment content: %v", err)
return fmt.Errorf("无法输入评论内容: %w", err)
}
humanize.Delay(ctx, humanize.AfterType)
submitButton, err := page.Element("div.bottom button.submit")
if err != nil {
logrus.Warnf("Failed to find submit button: %v", err)
return fmt.Errorf("未找到提交按钮: %w", err)
}
if err := humanize.Click(submitButton); err != nil {
logrus.Warnf("Failed to click submit button: %v", err)
return fmt.Errorf("无法点击提交按钮: %w", err)View on GitHub (pinned to 332d196854)
Solutions
- Inspect the live editor DOM and update the p.content-input selector to match current markup
- Confirm the account can comment manually in a browser (no shadowban/restriction)
- Wait for the editor element with a timeout before typing instead of querying immediately
Example fix
// before
elem2, err := page.Element("div.input-box div.content-edit p.content-input")
// after
elem2, err := page.Element("div.input-box div.content-edit p.content-input", rod.El{ "timeout": 5 * time.Second }) // give editor time to render / update selector per live DOM Defensive patterns
Strategy: try-catch
Validate before calling
// 先确认编辑器元素存在且可见再操作(若库允许注入等待逻辑)
page.MustElement("div.input-box div.content-edit p.content-input") Try / catch
err := svc.PostComment(ctx, feedID, content)
if err != nil && strings.Contains(err.Error(), "未找到评论输入区域") {
// 多为 DOM 变更或账号受限,人工核对页面后更新选择器或换号
log.Warnf("评论输入区未找到: %v", err)
} Prevention
- 改版后用真实浏览器核对编辑器 DOM 结构
- 确认账号未被限流/禁评
- 先点击展开编辑器再查找输入节点
When it happens
Trigger: The click focused nothing (editor never opened), the editor markup differs (new XHS UI uses a different tag/class), or the comment box is visually present but disabled for the account.
Common situations: DOM changes from XHS frontend releases; account in a restricted state where typing is blocked; clicking the wrong element because the selector matched a decorative span.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/4e336ee419084661.
Report an issue: GitHub.