From c9002d06e8013305b6efe16a0c3165aa232c48df Mon Sep 17 00:00:00 2001 From: zy Date: Sun, 28 Sep 2025 22:41:31 +0800 Subject: [PATCH] publish: update publish, rm pop-cover (#176) THANKS: @lmxdawn CLOSE: #172 --- xiaohongshu/publish.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/xiaohongshu/publish.go b/xiaohongshu/publish.go index e07a595..b53003c 100644 --- a/xiaohongshu/publish.go +++ b/xiaohongshu/publish.go @@ -11,6 +11,7 @@ import ( "github.com/go-rod/rod/lib/input" "github.com/go-rod/rod/lib/proto" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) // PublishImageContent 发布图文内容 @@ -31,9 +32,14 @@ const ( func NewPublishImageAction(page *rod.Page) (*PublishAction, error) { - pp := page.Timeout(60 * time.Second) + pp := page.Timeout(180 * time.Second) - pp.MustNavigate(urlOfPublic) + pp.MustNavigate(urlOfPublic).MustWaitIdle().MustWaitDOMStable() + time.Sleep(1 * time.Second) + + logrus.Info("navigate to publish page success") + + removePopCover(page) // 移除弹窗封面 pp.MustElement(`div.upload-content`).MustWaitVisible() slog.Info("wait for upload-content visible success") @@ -96,6 +102,19 @@ func (p *PublishAction) Publish(ctx context.Context, content PublishImageContent return nil } +func removePopCover(page *rod.Page) { + + has, elem, err := page.Has("div.d-popover") + if err != nil { + return + } + + if has { + elem.MustRemove() + } + +} + func uploadImages(page *rod.Page, imagesPaths []string) error { pp := page.Timeout(30 * time.Second)