登录(兼容URL和CK格式) Args: url: 登录URL 或 CK字符串(sessionId=xxx;_login_mobile_=xxx;_login_user_id_=xxx) timeout: 超时时间(秒) Returns: tuple: (是否成功, user_id, 手机号)
(self, url: str, timeout: int = PROXY_TIMEOUT)
| 381 | return None |
| 382 | |
| 383 | def login(self, url: str, timeout: int = PROXY_TIMEOUT) -> tuple[bool, str, str]: |
| 384 | """ |
| 385 | 登录(兼容URL和CK格式) |
| 386 | |
| 387 | Args: |
| 388 | url: 登录URL 或 CK字符串(sessionId=xxx;_login_mobile_=xxx;_login_user_id_=xxx) |
| 389 | timeout: 超时时间(秒) |
| 390 | |
| 391 | Returns: |
| 392 | tuple: (是否成功, user_id, 手机号) |
| 393 | """ |
| 394 | try: |
| 395 | decoded_input = unquote(url) |
| 396 | if decoded_input.startswith('sessionId=') or '_login_mobile_=' in decoded_input: |
| 397 | cookie_dict = {} |
| 398 | for item in decoded_input.split(';'): |
| 399 | item = item.strip() |
| 400 | if '=' in item: |
| 401 | k, v = item.split('=', 1) |
| 402 | cookie_dict[k] = v |
| 403 | for k, v in cookie_dict.items(): |
| 404 | self.session.cookies.set(k, v, domain='mcs-mimp-web.sf-express.com') |
| 405 | user_id = cookie_dict.get('_login_user_id_', '') |
| 406 | phone = cookie_dict.get('_login_mobile_', '') |
| 407 | if phone: |
| 408 | return True, user_id, phone |
| 409 | else: |
| 410 | return False, '', '' |
| 411 | else: |
| 412 | decoded_url = unquote(url) |
| 413 | self.session.get(decoded_url, headers=self.headers, timeout=timeout) |
| 414 | cookies = self.session.cookies.get_dict() |
| 415 | user_id = cookies.get('_login_user_id_', '') |
| 416 | phone = cookies.get('_login_mobile_', '') |
| 417 | if phone: |
| 418 | return True, user_id, phone |
| 419 | else: |
| 420 | return False, '', '' |
| 421 | except Exception as e: |
| 422 | print(f'登录异常: {str(e)}') |
| 423 | return False, '', '' |
| 424 | |
| 425 | |
| 426 | # ==================== 任务执行器 ==================== |