feat(07-01): implement ZhihuLogin QR code login class

TDD GREEN phase - implementation passes all 8 tests:

- ZhihuLoginResult: Pydantic model for login results
- ZhihuLogin: Main class with QR code login flow
  - LOGIN_URL: https://www.zhihu.com/signin
  - CANVAS_SELECTORS: Multiple fallback selectors for QR canvas
  - _find_qrcode_canvas(): Find canvas with fallback selectors
  - _save_qrcode_image(): Save QR code to intermediate directory
  - check_login_cookie(): Detect z_c0 cookie for login state
  - get_cookies_str(): Extract cookie string from context
  - _wait_for_login(): Poll with configurable timeout (tenacity)
  - login_by_qrcode(): Main entry point for login flow

Key design decisions:
- Uses tenacity Retrying for configurable timeout
- QR code saved to intermediate_path with timestamp
- Multiple canvas selectors for robustness
- Proper browser lifecycle management

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-17 17:54:06 +08:00
parent 771ca554b3
commit 072d83da35
3 changed files with 227 additions and 4 deletions
+4
View File
@@ -2,3 +2,7 @@
Provides authentication and cookie management functionality.
"""
from .zhihu_login import ZhihuLogin, ZhihuLoginResult
__all__ = ["ZhihuLogin", "ZhihuLoginResult"]