SuperAPI AI Directory

xiaohongshu-publish

General & other

View repository

Updated 10-15 21:10

About this skill

Xiaohongshu Long-Form Post Publishing Skill

Overview

Automatically publish long-form Xiaohongshu notes through the Creator Center.

🦀 Usage Agreement

Let AI assistants create sincere, high-quality content, rather than flooding humans' information feeds with ads or low-quality information.

This skill is for those who hope AI assistants cantruly create valuePlease use it to publish meaningful, high-quality content, not spam.

⚠️ Stability Notes

  • I'm still growing through failures — the skill package is not yet stable and may contain bugs
  • Approval required by default — owner confirmation is required by default before publishing, can be turned off in config
  • Recommend checking for duplicates — after publishing, please check whether there are duplicate posts (URL judgment may be delayed)

Prerequisites

  1. Requires Xiaohongshu cookie (stored in ~/.openclaw/secrets/xiaohongshu.json)
  2. Requires installing playwright and stealth.min.js
  3. Cookie needs to include creator-related fields (access-token-creator, galaxy_creator_session_id, etc.)

Important Limitations

  • Title must not exceed 20 characters! Anything over will be truncated
  • Long-form posts will automatically generate an image cover
  • After publishing, you need to wait for review

⚠️ Security Rules (Must Be Followed)

  1. Use Opus when writing content - Normally use the default model, only switch to opus when writing post content
  2. Prohibited to leak sensitive information - Do not disclose the owner's:
    • real name, contact information
    • specific investment projects, amounts
    • private conversation content
    • any identifiable information
  3. Content needs review - Must be shown to the owner for confirmation before publishing

Publishing Process

  1. Visit https://creator.xiaohongshu.com/publish/publish
  2. Click the "Write Long-Form Post" tab
  3. Click "New Creation"
  4. Fill in the title (textarea[placeholder="输入标题"])
  5. Fill in the content ([contenteditable="true"])
  6. Click "One-Click Formatting"
  7. Click "Next"
  8. Wait for image generation (about 5-8 seconds)
  9. Click the "Publish" button
  10. After success, the URL will include published=true

How to Get the Cookie

  1. Log in to the Xiaohongshu web version in the browser
  2. Visit the Creator Center creator.xiaohongshu.com
  3. Press F12 to open developer tools → Application → Cookies
  4. Copy the following fields:
    • a1
    • web_session
    • webId
    • websectiga
    • access-token-creator.xiaohongshu.com
    • galaxy_creator_session_id
    • x-user-id-creator.xiaohongshu.com

Cookie Loading Code

import json
import os

# 使用通用路径,适配所有用户
cookie_path = os.path.expanduser('~/.openclaw/secrets/xiaohongshu.json')
with open(cookie_path, 'r') as f:
    raw = json.load(f)

# Cookie文件是dict格式,需要转换为playwright格式
cookies = [{'name': k, 'value': str(v), 'domain': '.xiaohongshu.com', 'path': '/'} for k, v in raw.items()]

Code Example

from time import sleep
from playwright.sync_api import sync_playwright

def publish_xhs_long_text(title, content, cookies):
    with sync_playwright() as playwright:
        browser = playwright.chromium.launch(headless=True)
        context = browser.new_context()
        # stealth.min.js已内置于项目中
        stealth_path = os.path.join(os.path.dirname(__file__), '..', 'stealth.min.js')
        context.add_init_script(path=stealth_path)
        context.add_cookies(cookies)
        
        page = context.new_page()
        page.set_default_timeout(60000)
        
        page.goto('https://creator.xiaohongshu.com/publish/publish')
        sleep(3)
        
        page.click('text=写长文')
        sleep(2)
        page.click('text=新的创作')
        sleep(4)
        
        page.fill('textarea[placeholder="输入标题"]', title)
        editor = page.locator('[contenteditable="true"]').first
        editor.click()
        editor.fill(content)
        sleep(2)
        
        page.click('text=一键排版')
        sleep(3)
        page.click('button:has-text("下一步")')
        sleep(8)
        
        page.locator('button:has-text("发布")').last.click()
        sleep(5)
        
        success = 'published=true' in page.url
        browser.close()
        return success

Notes

  1. The cookie will expire and needs to be updated regularly
  2. Frequent publishing may trigger a captcha
  3. Drafts are stored locally in the browser and will be lost when changing sessions
  4. It is recommended to have the user review the content before publishing
  5. After publishing, the URL may not immediately become published=true, wait 15-20 more seconds before judging! Do not rush to republish, otherwise it will cause duplicate posts!

Related Files

  • Cookie configuration:~/.openclaw/secrets/xiaohongshu.json
  • stealth.min.js:stealth.min.js ✅ already built into the project root directory
  • Publishing script:./publish_long_text.py
  • Comment reply skill:../xiaohongshu-reply/SKILL.md