fix: 适配小红书创作者中心页面更新 (#394) (#395)

- 发布按钮选择器改为 .publish-page-publish-btn button.bg-red
- 定时发布从 radio 改为 switch 开关 (.post-time-wrapper .d-switch)
- 日期时间输入改为单个输入框 (.date-picker-container input)
- 视频发布页面等待策略从 MustWaitIdle 改为 WaitLoad

Fixes #394

Co-authored-by: tanjun <tanjun@tanjundeMac-mini.local>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
tan jun
2026-02-04 01:38:28 +08:00
committed by GitHub
parent c6be973b3c
commit 5c76f976ea
2 changed files with 38 additions and 103 deletions

View File

@@ -10,6 +10,7 @@ import (
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/proto"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
// PublishVideoContent 发布视频内容
@@ -21,14 +22,26 @@ type PublishVideoContent struct {
ScheduleTime *time.Time // 定时发布时间nil 表示立即发布
}
// NewPublishVideoAction 进入发布页并切换到上传视频
// NewPublishVideoAction 进入发布页并切换到"上传视频"
func NewPublishVideoAction(page *rod.Page) (*PublishAction, error) {
pp := page.Timeout(300 * time.Second)
pp.MustNavigate(urlOfPublic).MustWaitIdle().MustWaitDOMStable()
if err := pp.Navigate(urlOfPublic); err != nil {
return nil, errors.Wrap(err, "导航到发布页面失败")
}
// 使用 WaitLoad 代替 WaitIdle更宽松
if err := pp.WaitLoad(); err != nil {
logrus.Warnf("等待页面加载出现问题: %v继续尝试", err)
}
time.Sleep(2 * time.Second)
if err := pp.WaitDOMStable(time.Second, 0.1); err != nil {
logrus.Warnf("等待 DOM 稳定出现问题: %v继续尝试", err)
}
time.Sleep(1 * time.Second)
if err := mustClickPublishTab(page, "上传视频"); err != nil {
if err := mustClickPublishTab(pp, "上传视频"); err != nil {
return nil, errors.Wrap(err, "切换到上传视频失败")
}
@@ -90,7 +103,7 @@ func waitForPublishButtonClickable(page *rod.Page) (*rod.Element, error) {
maxWait := 10 * time.Minute
interval := 1 * time.Second
start := time.Now()
selector := "button.publishBtn"
selector := ".publish-page-publish-btn button.bg-red"
slog.Info("开始等待发布按钮可点击(视频)")