From 9ee583afcb3520dba3be0532555965785cdcc3f8 Mon Sep 17 00:00:00 2001 From: mshe <666666666@666666666.666666666> Date: Mon, 8 Jun 2026 17:27:51 +0800 Subject: [PATCH] fix bugs --- spider/mail_qq.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/spider/mail_qq.py b/spider/mail_qq.py index f01294a..426aea5 100644 --- a/spider/mail_qq.py +++ b/spider/mail_qq.py @@ -9,11 +9,11 @@ import logging logging.basicConfig(level=logging.INFO) # 日志会输出到 stderr,不会污染 stdout logging.info("服务器启动") -def save_login_state(auth_file, keyword, display=0): +def save_login_state(auth_file, keyword): with sync_playwright() as p: os.makedirs(os.path.dirname(auth_file), exist_ok=True) # headless=False 表示显示浏览器窗口,方便用户扫码登录 - browser = p.chromium.launch(headless=False,env={"DISPLAY": display}) + browser = p.chromium.launch(headless=False) context = browser.new_context() page = context.new_page() login_success = False @@ -86,11 +86,11 @@ def extract_cookies_from_auth(auth_file): return cookies -def crawl_with_saved_state(auth_file,display=0): +def crawl_with_saved_state(auth_file): with sync_playwright() as p: # 加载之前保存的登录状态 logging.info(f"加载认证文件: {auth_file}") - browser = p.chromium.launch(headless=False,env={"DISPLAY": display}) # 可以无头模式了 + browser = p.chromium.launch(headless=False) # 可以无头模式了 context = browser.new_context(storage_state=auth_file) page = context.new_page() page.goto('https://mail.qq.com') @@ -111,7 +111,7 @@ def crawl_with_saved_state(auth_file,display=0): browser.close() -def start(account, display=0): +def start(account): logging.info(f"用户名{account}") if not account: logging.error("请输入用户名") @@ -124,13 +124,13 @@ def start(account, display=0): file_age_minutes = (time.time() - os.path.getmtime(file_path)) / 60 if file_age_minutes > 30: logging.warning("认证文件已过期,请重新登录") - save_login_state(file_path, "收件箱", display) + save_login_state(file_path, "收件箱") else: logging.info("检测到认证文件,尝试使用保存的登录状态进行爬取") - crawl_with_saved_state(file_path,display) + crawl_with_saved_state(file_path) else: logging.info("未检测到认证文件,启动登录流程") - save_login_state(file_path, "收件箱",display) + save_login_state(file_path, "收件箱") if __name__ == '__main__': start("123", display=0) \ No newline at end of file