- Remove platform-specific configurations from base_config.py
- Create separate config files for each platform in their respective directories
- Update import statements in core files to use new platform-specific config modules
- Clean up unused and deprecated configuration options
- BilibiliClient:
- Improve wbi_img_urls handling for better compatibility
- Add error handling for missing or invalid 'is_end' and 'next' in comment cursor
- BilibiliCrawler:
- Fix daily limit logic for keyword-based searches
- Improve logging and break conditions for max notes count limits
- Ensure proper tracking of total notes crawled for each keyword
This commit introduces several improvements to enhance the stability and functionality of the Bilibili crawler.
- **Add Retry Logic:** Implement a retry mechanism with exponential backoff when fetching video comments. This makes the crawler more resilient to transient network issues or API errors.
- **Improve Error Handling:** Add a `try...except` block to handle potential `JSONDecodeError` in the Bilibili client, preventing crashes when the API returns an invalid response.
- **Ensure Clean Shutdown:** Refactor `main.py` to use a `try...finally` block, guaranteeing that the crawler and database connections are properly closed on exit, error, or `KeyboardInterrupt`.
- **Update Default Config:** Adjust default configuration values to increase concurrency, enable word cloud generation by default, and refine the Bilibili search mode for more practical usage.
Refactors the Bilibili keyword search functionality to provide more flexible crawling strategies and corrects a flaw in how crawl limits were applied.
Previously, the `ALL_DAY` boolean flag offered a rigid choice for time-based searching and contained a logical issue where `CRAWLER_MAX_NOTES_COUNT` was incorrectly applied on a per-day basis instead of as an overall total.
This commit introduces the `BILI_SEARCH_MODE` configuration option with three distinct modes:
- `normal`: The default search behavior without time constraints.
- `all_in_time_range`: Maximizes data collection within a specified date range, replicating the original intent of `ALL_DAY=True`.
- `daily_limit_in_time_range`: A new mode that strictly enforces both the daily `MAX_NOTES_PER_DAY` and the total `CRAWLER_MAX_NOTES_COUNT` limits across the entire date range.
This change resolves the limit logic bug and gives users more precise control over the crawling process.
Changes include:
- Modified `config/base_config.py` to replace `ALL_DAY` with `BILI_SEARCH_MODE`.
- Refactored `media_platform/bilibili/core.py` to implement the new search mode logic.
除了原先的max_id参数外,max_id_type参数也附加在上一次api结果的解析中,初始为0,但随着获取的评论越来越多,会更改为1。
此外,修改了WeiboClient类的request函数,将返回的ok_code异常处理进行了优化,细分为0,1,else...。这样即便获取到的max_id和max_id_type为None,也不会触发像'>' not supported between instances of 'NoneType' and 'int'这样模棱两可的异常提示,方便溯源问题所在,即api响应错误。
对于评论的数据获取不全的情况,在浏览器中获取显示的评论数量为1000+,更改此次提交前获取的个数为308条,更改后为319条,使用网页端打开手动刷评论的最后一条和程序获取的最后一条内容一致,可能是微博默认开启的精选评论功能导致无法获取所有的微博...