Complete Guide to Xiaohongshu AI Publisher: Automate Content Creation and Publishing
⏱️ Estimated Reading Time: 8 minutes
Introduction
Xiaohongshu (Little Red Book, also known as RedNote) has become one of China’s most influential social commerce platforms, with over 300 million monthly active users. For content creators and marketers looking to establish a presence on this platform, the xhs_ai_publisher project offers a powerful solution for automating content creation and publishing workflows.
This comprehensive tutorial will guide you through setting up and using the xhs_ai_publisher tool, which combines AI-powered content generation with automated publishing capabilities using Selenium-based RPA (Robotic Process Automation).
What is xhs_ai_publisher?
The xhs_ai_publisher is an open-source Python project that serves as an AI-powered operation assistant for Xiaohongshu. It consists of two main components:
🤖 AI Content Generation
- Automated Content Creation: Generates Xiaohongshu-style posts including titles, descriptions, and hashtags
- Image Integration: Automatically selects and processes relevant images for posts
- Style Optimization: Ensures content matches Xiaohongshu’s unique writing style and formatting conventions
🎯 Automated Publishing
- RPA Automation: Uses Selenium WebDriver to simulate user interactions
- Multi-Account Support: Manages multiple Xiaohongshu accounts simultaneously
- Scheduled Publishing: Supports timed and batch publishing features
- Browser Fingerprinting: Includes anti-detection measures for automation safety
Key Features and Capabilities
Feature | Description | Benefits |
---|---|---|
🎨 AI Content Generation | Creates engaging posts with proper formatting | Saves time on content creation |
📱 Multi-Account Management | Handle multiple Xiaohongshu accounts | Scale operations efficiently |
🖼️ Automated Image Processing | Smart image selection and optimization | Professional visual content |
🔒 Proxy Support | HTTP/HTTPS/SOCKS5 proxy configuration | Enhanced privacy and security |
🌐 Browser Automation | Selenium-based publishing automation | Reliable posting workflow |
📊 User Management System | Comprehensive account and profile management | Organized operations |
System Requirements
Before starting, ensure your system meets these requirements:
Component | Requirement | Recommendation |
---|---|---|
🐍 Python | 3.8+ | Latest stable version |
🌐 Chrome Browser | Latest version | For Selenium automation |
💾 Memory | 4GB+ | 8GB+ recommended |
💿 Storage | 2GB+ | For dependencies and data |
🌍 Network | Stable internet | VPN may be required |
Installation Guide
The project supports multiple installation methods across different operating systems.
🚀 Quick Installation (Recommended)
Choose the appropriate installation script for your operating system:
🍎 macOS Installation
# 1️⃣ Clone the repository
git clone https://github.com/BetaStreetOmnis/xhs_ai_publisher.git
cd xhs_ai_publisher
# 2️⃣ Run installation script
chmod +x install_mac.sh
./install_mac.sh
# 3️⃣ Start the application
./启动程序.sh
Features:
- ✅ Automatic Python environment detection and installation
- ✅ Homebrew installation (if needed)
- ✅ Support for both Apple Silicon and Intel chips
- ✅ Complete dependency management and virtual environment setup
🐧 Linux Installation
# 1️⃣ Clone the repository
git clone https://github.com/BetaStreetOmnis/xhs_ai_publisher.git
cd xhs_ai_publisher
# 2️⃣ Run installation script
chmod +x install.sh
./install.sh
# 3️⃣ Start the application
./启动程序.sh
Supported Distributions:
- ✅ Ubuntu/Debian family
- ✅ RHEL/CentOS/Rocky Linux
- ✅ Fedora
- ✅ openSUSE/SLES
- ✅ Arch Linux/Manjaro
💻 Windows Installation
# 1️⃣ Clone the repository
git clone https://github.com/BetaStreetOmnis/xhs_ai_publisher.git
cd xhs_ai_publisher
# 2️⃣ Run installation script
install.bat
# 3️⃣ Start the application
启动程序.bat
Requirements:
- ✅ Windows 10/11
- ✅ Automatic Python installation (if needed)
- ✅ Complete dependency management
🔧 Manual Installation (Advanced Users)
# 1️⃣ Clone the repository
git clone https://github.com/BetaStreetOmnis/xhs_ai_publisher.git
cd xhs_ai_publisher
# 2️⃣ Create virtual environment
python -m venv venv
# 3️⃣ Activate virtual environment
# Linux/Mac:
source venv/bin/activate
# Windows:
venv\Scripts\activate
# 4️⃣ Install dependencies
pip install -r requirements.txt
# 5️⃣ Initialize database (optional)
python init_db.py
# 6️⃣ Start the application
python main.py
Configuration Setup
🔑 Environment Configuration
Create and configure your .env
file:
# AI Configuration
OPENAI_API_KEY=your_openai_api_key_here
AI_MODEL=gpt-3.5-turbo
MAX_TOKENS=2000
TEMPERATURE=0.7
# Xiaohongshu Configuration
XHS_USERNAME=your_username
XHS_PASSWORD=your_password
# Proxy Configuration (Optional)
PROXY_TYPE=http
PROXY_HOST=your_proxy_host
PROXY_PORT=your_proxy_port
PROXY_USERNAME=your_proxy_username
PROXY_PASSWORD=your_proxy_password
# Browser Configuration
HEADLESS_MODE=false
BROWSER_TIMEOUT=30
⚙️ Advanced Configuration
Edit the config.py
file for advanced settings:
# AI Configuration
AI_CONFIG = {
"model": "gpt-3.5-turbo",
"max_tokens": 2000,
"temperature": 0.7,
"system_prompt": "You are a Xiaohongshu content creator..."
}
# Browser Configuration
BROWSER_CONFIG = {
"headless": False,
"user_agent": "Mozilla/5.0...",
"viewport": {"width": 1920, "height": 1080},
"page_load_timeout": 30
}
# Publishing Configuration
PUBLISH_CONFIG = {
"auto_publish": False,
"delay_range": [3, 8],
"max_retry": 3,
"screenshot_on_error": True
}
Step-by-Step Usage Guide
1. 🚀 Application Startup
Launch the application using one of these methods:
# Method 1: Using startup script
./启动程序.sh
# Method 2: Direct Python execution
python main.py
# Method 3: Using specific config
python main.py --config custom_config.py
2. 👤 User Management
- Access User Management: Click the “User Management” button in the main interface
- Add New User: Configure account details and preferences
- Proxy Settings: Set up proxy configuration for each account
- Browser Fingerprinting: Configure unique browser fingerprints to avoid detection
3. 📱 Account Authentication
# Example authentication flow
def authenticate_account(phone_number):
"""
Authenticate Xiaohongshu account
"""
# 1. Enter phone number
driver.find_element(By.ID, "phone").send_keys(phone_number)
# 2. Request verification code
driver.find_element(By.ID, "send_code").click()
# 3. Enter verification code (manual input required)
verification_code = input("Enter verification code: ")
driver.find_element(By.ID, "code").send_keys(verification_code)
# 4. Submit and save session
driver.find_element(By.ID, "login").click()
return True
4. ✍️ Content Creation Workflow
Automated Content Generation
# Example content generation
def generate_content(topic):
"""
Generate Xiaohongshu-style content
"""
prompt = f"""
Create a Xiaohongshu post about: {topic}
Requirements:
- Engaging title with emojis
- 200-300 characters description
- 5-8 relevant hashtags
- Xiaohongshu writing style
"""
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": prompt}],
max_tokens=2000,
temperature=0.7
)
return response.choices[0].message.content
Manual Content Input
- Topic Input: Enter your desired topic in the main input field
- Generate Content: Click “Generate Content” button
- Review and Edit: Review AI-generated content and make adjustments
- Image Selection: Choose or upload relevant images
5. 🖼️ Image Management
The tool provides comprehensive image handling:
# Image processing example
def process_images(topic, num_images=3):
"""
Process and optimize images for Xiaohongshu
"""
# 1. Search for relevant images
images = search_stock_images(topic)
# 2. Resize and optimize
processed_images = []
for img in images[:num_images]:
# Xiaohongshu optimal dimensions: 3:4 ratio
resized = img.resize((750, 1000))
processed_images.append(resized)
# 3. Add watermarks or filters if needed
return processed_images
6. 📤 Publishing Process
Automated Publishing
def publish_post(title, content, images, hashtags):
"""
Automate post publishing to Xiaohongshu
"""
try:
# 1. Navigate to create post page
driver.get("https://creator.xiaohongshu.com/publish/publish")
# 2. Upload images
for img_path in images:
upload_element = driver.find_element(By.CSS_SELECTOR, "input[type='file']")
upload_element.send_keys(img_path)
time.sleep(2)
# 3. Add title and content
title_field = driver.find_element(By.CSS_SELECTOR, "input[placeholder*='title']")
title_field.send_keys(title)
content_field = driver.find_element(By.CSS_SELECTOR, "textarea")
content_field.send_keys(f"{content}\n\n{' '.join(hashtags)}")
# 4. Publish
publish_button = driver.find_element(By.CSS_SELECTOR, "button[data-testid='publish']")
publish_button.click()
return True
except Exception as e:
logger.error(f"Publishing failed: {e}")
return False
Scheduled Publishing
def schedule_post(content, publish_time):
"""
Schedule post for future publishing
"""
scheduler = BackgroundScheduler()
scheduler.add_job(
func=publish_post,
trigger="date",
run_date=publish_time,
args=[content['title'], content['text'], content['images'], content['hashtags']]
)
scheduler.start()
Advanced Features
🔒 Proxy Configuration
Configure different proxy types for enhanced security:
# Proxy configuration examples
PROXY_CONFIGS = {
"http": {
"proxy_type": "http",
"host": "proxy.example.com",
"port": 8080,
"username": "user",
"password": "pass"
},
"socks5": {
"proxy_type": "socks5",
"host": "socks.example.com",
"port": 1080
}
}
def setup_proxy(driver, config):
"""Setup proxy for browser session"""
proxy = Proxy()
proxy.proxy_type = ProxyType.MANUAL
proxy.http_proxy = f"{config['host']}:{config['port']}"
proxy.ssl_proxy = f"{config['host']}:{config['port']}"
capabilities = webdriver.DesiredCapabilities.CHROME
proxy.add_to_capabilities(capabilities)
return capabilities
🔍 Anti-Detection Measures
Implement browser fingerprinting and behavior randomization:
def setup_stealth_browser():
"""Configure browser for stealth operation"""
options = webdriver.ChromeOptions()
# Disable automation flags
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
# Random user agent
options.add_argument(f"--user-agent={get_random_user_agent()}")
# Random viewport
viewport = get_random_viewport()
options.add_argument(f"--window-size={viewport['width']},{viewport['height']}")
driver = webdriver.Chrome(options=options)
# Execute stealth script
driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
return driver
📊 Analytics and Monitoring
Track posting performance and system health:
def track_post_performance(post_id):
"""Monitor post engagement metrics"""
metrics = {
"views": 0,
"likes": 0,
"comments": 0,
"shares": 0,
"timestamp": datetime.now()
}
# Scrape metrics from post page
driver.get(f"https://xiaohongshu.com/explore/{post_id}")
try:
likes = driver.find_element(By.CSS_SELECTOR, "[data-testid='like-count']").text
metrics["likes"] = int(likes.replace("k", "000") if "k" in likes else likes)
except:
pass
# Save to database
save_metrics(post_id, metrics)
return metrics
Troubleshooting Guide
Common Issues and Solutions
1. 🚫 Login Issues
Problem: Cannot authenticate with Xiaohongshu account
Solutions:
def fix_login_issues():
"""Common login troubleshooting steps"""
steps = [
"1. Clear browser cache and cookies",
"2. Update Chrome browser to latest version",
"3. Check proxy configuration",
"4. Verify phone number format",
"5. Use different user agent string",
"6. Enable manual captcha solving"
]
return steps
2. 🖼️ Image Upload Failures
Problem: Images fail to upload or process
Solutions:
def fix_image_issues():
"""Image troubleshooting checklist"""
checks = [
"Verify image format (JPG, PNG supported)",
"Check image size (max 10MB)",
"Ensure proper aspect ratio (3:4 recommended)",
"Validate image dimensions (min 750px width)",
"Check available disk space",
"Verify network connectivity"
]
return checks
3. 🔄 Automation Detection
Problem: Xiaohongshu detects automation
Solutions:
def avoid_detection():
"""Anti-detection best practices"""
practices = [
"Use residential proxies",
"Randomize timing between actions",
"Implement human-like mouse movements",
"Rotate user agents regularly",
"Limit posting frequency",
"Use different browser fingerprints"
]
return practices
Best Practices and Tips
📝 Content Creation Best Practices
- Understand Xiaohongshu Culture: Research trending topics and popular formats
- Use Appropriate Hashtags: Include 5-8 relevant hashtags for better discoverability
- Optimize Image Quality: Use high-resolution images with proper lighting
- Maintain Consistency: Post regularly to build audience engagement
- Monitor Trends: Stay updated with platform algorithm changes
🔒 Security Considerations
# Security checklist
SECURITY_CHECKLIST = {
"account_safety": [
"Use strong, unique passwords",
"Enable two-factor authentication",
"Regularly rotate access credentials",
"Monitor account activity logs"
],
"automation_safety": [
"Implement rate limiting",
"Use quality proxies",
"Randomize automation patterns",
"Monitor platform policy changes"
],
"data_protection": [
"Encrypt sensitive configuration",
"Secure API keys properly",
"Implement access controls",
"Regular backup procedures"
]
}
Performance Optimization
⚡ Speed Optimization
def optimize_performance():
"""Performance optimization techniques"""
optimizations = {
"parallel_processing": "Use threading for multiple accounts",
"cache_management": "Implement intelligent caching for images and content",
"resource_pooling": "Reuse browser instances when possible",
"database_optimization": "Index frequently queried fields",
"memory_management": "Regular cleanup of unused objects"
}
return optimizations
📊 Monitoring and Logging
import logging
from datetime import datetime
def setup_logging():
"""Configure comprehensive logging"""
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(f'xhs_publisher_{datetime.now().strftime("%Y%m%d")}.log'),
logging.StreamHandler()
]
)
# Create specialized loggers
automation_logger = logging.getLogger('automation')
content_logger = logging.getLogger('content_generation')
error_logger = logging.getLogger('errors')
return {
'automation': automation_logger,
'content': content_logger,
'errors': error_logger
}
Future Roadmap and Updates
The xhs_ai_publisher project continues to evolve with planned enhancements:
🚀 Upcoming Features
- ✅ Basic Functionality: Content generation and publishing (Completed)
- ✅ User Management: Multi-account support (Completed)
- ✅ Proxy Configuration: Network proxy support (Completed)
- 🔄 Content Library: Material management system (In Progress)
- 🔄 Template Library: Preset template system (In Progress)
- 🔄 Analytics Dashboard: Publishing performance analysis (Planned)
- 🔄 API Interface: Open API endpoints (Planned)
- 🔄 Mobile Support: Mobile application (Planned)
Conclusion
The xhs_ai_publisher tool represents a significant advancement in social media automation, specifically tailored for the Xiaohongshu platform. By combining AI-powered content generation with sophisticated automation capabilities, it enables content creators and marketers to scale their operations while maintaining quality and authenticity.
Key Takeaways
- Comprehensive Solution: The tool covers the entire content lifecycle from creation to publishing
- Flexible Configuration: Extensive customization options for different use cases
- Security-Focused: Built-in anti-detection and security measures
- Active Development: Ongoing improvements and feature additions
- Community-Driven: Open-source project with active contributor community
Getting Started
To begin your journey with xhs_ai_publisher:
- Install the Tool: Follow the installation guide for your operating system
- Configure Settings: Set up your AI API keys and proxy configurations
- Create Content: Start with simple posts to understand the workflow
- Monitor Performance: Track results and optimize your strategy
- Join Community: Engage with other users for tips and troubleshooting
Whether you’re a content creator looking to streamline your workflow or a marketer aiming to scale your Xiaohongshu presence, this tool provides the foundation for automated, intelligent social media management.
📚 Additional Resources:
🌟 Star the project on GitHub if you find it helpful!