xpzouying/xiaohongshu-mcp · error

未找到评论输入框,该帖子可能不支持评论或网页端不可访问: %w

Error message

未找到评论输入框,该帖子可能不支持评论或网页端不可访问: %w

What it means

PostComment locates the comment input box on the post page via go-rod selector 'div.input-box div.content-edit span'. When page.Element cannot find it, the function fails with this wrapped error, warning that the post may not support comments or is not accessible via web.

Source

Thrown at xiaohongshu/comment_feed.go:44

	page := f.page.Timeout(60 * time.Second)

	url := makeFeedDetailURL(feedID, xsecToken)
	logrus.Infof("打开 feed 详情页: %s", url)

	// 导航到详情页
	page.MustNavigate(url)
	page.MustWaitDOMStable()
	humanize.Delay(ctx, humanize.AfterNavigate)

	// 检测页面是否可访问
	if err := checkPageAccessible(page); err != nil {
		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)
	}

View on GitHub (pinned to 332d196854)

Solutions

  1. Verify the feedID/url opens a real, comment-enabled post in a browser
  2. Re-login / refresh cookies so the page renders the authenticated comment UI
  3. Print page HTML on failure and update the CSS selector if the site DOM changed
  4. Check the post type: some posts (e.g. certain video or restricted posts) genuinely have no comment box

Example fix

// before
resp, _ := svc.PostComment(ctx, "stale-or-wrong-feed-id", "nice")
// after
if !postSupportsComments(feedID) { return errors.New("post does not allow comments") }
resp, _ := svc.PostComment(ctx, feedID, "nice")
Defensive patterns

Strategy: try-catch

Validate before calling

// 调用前确认帖子可访问且允许评论(浏览器或 API 侧校验 feed URL 有效性)
if feedID == "" || !strings.HasPrefix(feedURL, "https://www.xiaohongshu.com/") {
    return errors.New("无效的帖子链接")
}

Type guard

func isCommentablePage(selErr error) bool { return selErr != nil && strings.Contains(selErr.Error(), "未找到评论输入框") }

Try / catch

err := svc.PostComment(ctx, feedID, content)
if err != nil && strings.Contains(err.Error(), "未找到评论输入框") {
    // 帖子不支持评论或登录失效:不要盲目重试,先人工核查
    log.Warnf("帖子 %s 不可评论: %v", feedID, err)
}

Prevention

When it happens

Trigger: PostComment called with a feedID whose post has comments disabled/deleted, a non-existent or wrong feed URL, a page that requires login again, or a XHS DOM update changing the selector.

Common situations: Commenting on posts with comment restrictions (author-limited, banned topic); stale feedID from an old link; being logged out so the page renders a login wall instead of the comment box; site A/B tests renaming CSS classes.

Related errors


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