#!/usr/bin/env python3 # -*- coding: utf-8 -*- """修复quick_login - 使用池中浏览器时直接登录""" with open('/www/wwwroot/zsglpt/playwright_automation.py', 'r', encoding='utf-8') as f: content = f.read() # 找到quick_login方法并替换 old = ''' def quick_login(self, username: str, password: str, remember: bool = True): """快速登录 - 优先使用cookies,失败则正常登录""" # 尝试使用cookies if self.load_cookies(username):''' new = ''' def quick_login(self, username: str, password: str, remember: bool = True): """快速登录 - 使用池中浏览器时直接登录,否则尝试cookies""" # 如果已有浏览器实例(从池中获取),直接使用该浏览器登录 # 不尝试加载cookies,因为load_cookies会创建新浏览器覆盖池中的 if self.browser and self.browser.is_connected(): self.log("使用池中浏览器,直接登录") result = self.login(username, password, remember) if result.get('success'): self.save_cookies(username) result['used_cookies'] = False return result # 无现有浏览器时,尝试使用cookies if self.load_cookies(username):''' if old in content: content = content.replace(old, new) print("OK - quick_login已修复") else: print("WARNING - 未找到匹配内容,显示实际内容进行对比") import re match = re.search(r'def quick_login.*?(?=\n def |\n\nclass |\Z)', content, re.DOTALL) if match: print("实际内容前200字符:") print(repr(match.group(0)[:200])) with open('/www/wwwroot/zsglpt/playwright_automation.py', 'w', encoding='utf-8') as f: f.write(content) print("完成")