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>
43 lines
840 B
Go
43 lines
840 B
Go
package browser
|
|
|
|
import (
|
|
"github.com/go-rod/rod"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/xpzouying/headless_browser"
|
|
"github.com/xpzouying/xiaohongshu-mcp/cookies"
|
|
)
|
|
|
|
var (
|
|
browser *headless_browser.Browser
|
|
)
|
|
|
|
func Init(headless bool) error {
|
|
|
|
opts := []headless_browser.Option{
|
|
headless_browser.WithHeadless(headless),
|
|
}
|
|
|
|
// 加载 cookies
|
|
cookiePath := cookies.GetCookiesFilePath()
|
|
cookieLoader := cookies.NewLoadCookie(cookiePath)
|
|
|
|
if data, err := cookieLoader.LoadCookies(); err == nil {
|
|
opts = append(opts, headless_browser.WithCookies(string(data)))
|
|
logrus.Debugf("loaded cookies from filesuccessfully")
|
|
} else {
|
|
logrus.Warnf("failed to load cookies: %v", err)
|
|
}
|
|
|
|
browser = headless_browser.New(opts...)
|
|
|
|
return nil
|
|
}
|
|
|
|
func NewPage() *rod.Page {
|
|
return browser.NewPage()
|
|
}
|
|
|
|
func Close() {
|
|
browser.Close()
|
|
}
|