feat: improve Xiaohongshu authentication with automatic cookie persis…#773
Open
handysome6 wants to merge 1 commit intoNanmiCoder:mainfrom
Open
Conversation
…tence This commit implements a comprehensive improvement to the Xiaohongshu (小红书) authentication system to avoid repeated QR code scanning on every run. ## Key Features 1. **Automatic Cookie Management** - Auto-save cookies after successful QR code or phone login - Auto-load and validate saved cookies on subsequent runs - Smart fallback to configured login method if cookies are invalid 2. **New CookieManager Class** - Manages cookie persistence to `cookies/xhs_cookies.json` - Validates cookie age (warns about 30+ day old cookies) - Provides cookie info and cleanup methods 3. **Enhanced Login Flow** - Prioritizes saved cookies before prompting for login - Validates cookies with `pong()` check before use - Saves ALL cookies, not just `web_session` - Seamless authentication on subsequent runs 4. **New Configuration Option** - `AUTO_SAVE_AND_USE_COOKIES` (default: True) - Enables/disables automatic cookie management - Backward compatible with existing configurations ## Changes ### New Files - `media_platform/xhs/cookie_manager.py`: Cookie persistence utility - `docs/xiaohongshu_auth_improvement.md`: English documentation - `docs/xiaohongshu_auth_improvement_zh.md`: Chinese documentation ### Modified Files - `media_platform/xhs/login.py`: Enhanced cookie login, auto-save after login - `media_platform/xhs/core.py`: Improved authentication flow with cookie priority - `config/base_config.py`: Added AUTO_SAVE_AND_USE_COOKIES option - `.gitignore`: Added `/cookies/` directory to prevent cookie commits ## Benefits **Before**: Scan QR code every single run ❌ **After**: Scan QR code only once, then automatic authentication ✅ ## Security - Cookie directory automatically gitignored - Cookies stored locally with timestamps - No sensitive data committed to repository ## Documentation Comprehensive documentation provided in both English and Chinese, including: - Configuration guide - Usage examples - Troubleshooting tips - API reference - Migration guide Resolves the issue of repeated QR code authentication and significantly improves user experience for Xiaohongshu URL crawling.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…tence
This commit implements a comprehensive improvement to the Xiaohongshu (小红书) authentication system to avoid repeated QR code scanning on every run.
Key Features
Automatic Cookie Management
New CookieManager Class
cookies/xhs_cookies.jsonEnhanced Login Flow
pong()check before useweb_sessionNew Configuration Option
AUTO_SAVE_AND_USE_COOKIES(default: True)Changes
New Files
media_platform/xhs/cookie_manager.py: Cookie persistence utilitydocs/xiaohongshu_auth_improvement.md: English documentationdocs/xiaohongshu_auth_improvement_zh.md: Chinese documentationModified Files
media_platform/xhs/login.py: Enhanced cookie login, auto-save after loginmedia_platform/xhs/core.py: Improved authentication flow with cookie priorityconfig/base_config.py: Added AUTO_SAVE_AND_USE_COOKIES option.gitignore: Added/cookies/directory to prevent cookie commitsBenefits
Before: Scan QR code every single run ❌
After: Scan QR code only once, then automatic authentication ✅
Security
Documentation
Comprehensive documentation provided in both English and Chinese, including:
Resolves the issue of repeated QR code authentication and significantly improves user experience for Xiaohongshu URL crawling.