Complete implementation of xiaohongshu (Little Red Book) automation system: ### Core Features: - **QR Code Login**: Automated login with cookie persistence - **Content Publishing**: Post text, images with AI-powered descriptions - **Browser Management**: Headless Chrome automation via go-rod - **Cookie Persistence**: Session management for login state - **MCP Server**: Model Context Protocol integration for Claude ### Technical Components: - go-rod browser automation with stealth mode - MCP server for Claude Code integration - Cookie-based session management - Robust error handling and logging - Cross-platform compatibility ### API Endpoints: - Login status checking and QR code authentication - Content publishing with image upload support - Navigation and page interaction utilities This provides a complete foundation for xiaohongshu automation with proper session management and MCP integration. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
55 lines
998 B
Go
55 lines
998 B
Go
package cookies
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type Cookier interface {
|
|
LoadCookies() ([]byte, error)
|
|
SaveCookies(data []byte) error
|
|
}
|
|
|
|
type localCookie struct {
|
|
path string
|
|
}
|
|
|
|
func NewLoadCookie(path string) Cookier {
|
|
if path == "" {
|
|
panic("path is required")
|
|
}
|
|
|
|
if err := os.MkdirAll(filepath.Dir(path), 0644); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return &localCookie{
|
|
path: path,
|
|
}
|
|
}
|
|
|
|
// LoadCookies 从文件中加载 cookies。
|
|
func (c *localCookie) LoadCookies() ([]byte, error) {
|
|
|
|
data, err := os.ReadFile(c.path)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "failed to read cookies from tmp file")
|
|
}
|
|
|
|
return data, nil
|
|
}
|
|
|
|
// SaveCookies 保存 cookies 到文件中。
|
|
func (c *localCookie) SaveCookies(data []byte) error {
|
|
return os.WriteFile(c.path, data, 0644)
|
|
}
|
|
|
|
// GetCookiesFilePath 获取 cookies 文件路径。
|
|
func GetCookiesFilePath() string {
|
|
tmpDir := os.TempDir()
|
|
filePath := filepath.Join(tmpDir, "cookies.json")
|
|
return filePath
|
|
}
|