Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
X
xhs-publish-mcp
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
郭阔
xhs-publish-mcp
Commits
3fe25414
Commit
3fe25414
authored
Nov 11, 2026
by
郭阔
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check creator editor readiness before publishing
parent
64170d5f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
39 deletions
+26
-39
creator_session.go
xiaohongshu/creator_session.go
+26
-31
publish.go
xiaohongshu/publish.go
+0
-4
publish_video.go
xiaohongshu/publish_video.go
+0
-4
No files found.
xiaohongshu/creator_session.go
View file @
3fe25414
package
xiaohongshu
import
(
"net/url"
"time"
"github.com/go-rod/rod"
"github.com/pkg/errors"
"github.com/xpzouying/xiaohongshu-mcp/humanize"
)
const
(
urlOfCreatorHome
=
`https://creator.xiaohongshu.com/?source=official`
const
creatorSessionTimeout
=
15
*
time
.
Second
creatorSessionCookie
=
"galaxy_creator_session_id"
creatorSessionTimeout
=
15
*
time
.
Second
)
// ensureCreatorSession 浏览器里没有创作者中心会话时,先打开创作者中心首页,等会话建立
// ensureCreatorSession verifies the authenticated editor instead of relying on a
// cookie whose name and presence are controlled by the platform.
func
ensureCreatorSession
(
page
*
rod
.
Page
)
error
{
if
hasCreatorSession
(
page
)
{
return
nil
}
if
err
:=
page
.
Navigate
(
urlOfCreatorHome
);
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"打开创作者中心失败"
)
if
err
:=
page
.
Navigate
(
urlOfPublic
);
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"打开创作者中心编辑器失败"
)
}
deadline
:=
time
.
Now
()
.
Add
(
creatorSessionTimeout
)
var
lastPath
string
for
time
.
Now
()
.
Before
(
deadline
)
{
time
.
Sleep
(
500
*
time
.
Millisecond
)
if
hasCreatorSession
(
page
)
{
humanize
.
Delay
(
page
.
GetContext
(),
humanize
.
AfterNavigate
)
return
nil
info
,
err
:=
page
.
Info
()
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"读取创作者中心页面地址失败"
)
}
}
return
errors
.
New
(
"创作者中心登录失效,请重新扫码登录"
)
}
func
hasCreatorSession
(
page
*
rod
.
Page
)
bool
{
cks
,
err
:=
page
.
Browser
()
.
GetCookies
()
if
err
!=
nil
{
return
false
}
for
_
,
c
:=
range
cks
{
if
c
.
Name
==
creatorSessionCookie
{
return
true
current
,
err
:=
url
.
Parse
(
info
.
URL
)
if
err
!=
nil
{
return
errors
.
New
(
"无法解析创作者中心页面地址"
)
}
lastPath
=
current
.
Host
+
current
.
Path
if
current
.
Scheme
==
"https"
&&
current
.
Host
==
"creator.xiaohongshu.com"
&&
current
.
Path
==
"/publish/publish"
{
found
,
_
,
err
:=
page
.
Has
(
"div.creator-tab, .upload-input"
)
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"检查创作者中心编辑器失败"
)
}
if
found
{
return
nil
}
}
time
.
Sleep
(
500
*
time
.
Millisecond
)
}
return
false
return
errors
.
Errorf
(
"创作者中心编辑器未就绪(当前页面:%s),请检查页面是否要求登录"
,
lastPath
)
}
xiaohongshu/publish.go
View file @
3fe25414
...
...
@@ -54,10 +54,6 @@ func NewPublishImageAction(page *rod.Page) (*PublishAction, error) {
return
nil
,
err
}
if
err
:=
pp
.
Navigate
(
urlOfPublic
);
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"导航到发布页面失败"
)
}
if
err
:=
pp
.
WaitLoad
();
err
!=
nil
{
logrus
.
Warnf
(
"等待页面加载出现问题: %v,继续尝试"
,
err
)
}
...
...
xiaohongshu/publish_video.go
View file @
3fe25414
...
...
@@ -32,10 +32,6 @@ func NewPublishVideoAction(page *rod.Page) (*PublishAction, error) {
return
nil
,
err
}
if
err
:=
pp
.
Navigate
(
urlOfPublic
);
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"导航到发布页面失败"
)
}
// 使用 WaitLoad 代替 WaitIdle(更宽松)
if
err
:=
pp
.
WaitLoad
();
err
!=
nil
{
logrus
.
Warnf
(
"等待页面加载出现问题: %v,继续尝试"
,
err
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment