From cac31a29e0ea9e09dd3dd2cd27479db0060ea4f3 Mon Sep 17 00:00:00 2001 From: work Date: Thu, 21 Aug 2025 18:47:00 +0800 Subject: [PATCH] =?UTF-8?q?HEADLESS=20=E6=94=BE=E5=88=B0=E5=B8=B8=E9=87=8F?= =?UTF-8?q?=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- const.py | 3 +++ spider/task.py | 12 +++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/const.py b/const.py index 30efcff..6182cf2 100644 --- a/const.py +++ b/const.py @@ -31,3 +31,6 @@ api_url = "http://local.adspower.net:50325" # 显示缩放比例 1为100% DISPLAY_SCALE = 0.7 + +# 登录, 检查账号, 获取账号配置, 更新账号配置是否隐藏浏览器 +HEADLESS = True diff --git a/spider/task.py b/spider/task.py index b3d1b06..8fb0714 100644 --- a/spider/task.py +++ b/spider/task.py @@ -24,8 +24,6 @@ from const import BUCKET, BASE_PATH from exceptions import AuthException, OperationFailed from miniofile import client, put_object -# 登录, 检查账号, 获取账号配置, 更新账号配置是否隐藏浏览器 -HEADLESS = False def sleep(a, b=None): @@ -451,7 +449,7 @@ def playwright_get_user_profile(cookies, username=None): with sync_playwright() as playwright: update_windows_distinguish() browser = playwright.chromium.launch( - headless=HEADLESS, args=['--start-maximized'], executable_path=path + headless=const.HEADLESS, args=['--start-maximized'], executable_path=path ) context = browser.new_context(no_viewport=True) context.add_cookies(parse_cookies(cookies)) @@ -502,7 +500,7 @@ def playwright_set_user_profile(cookies, username=None, first_name=None, last_na with sync_playwright() as playwright: update_windows_distinguish() browser = playwright.chromium.launch( - headless=HEADLESS, args=['--start-maximized'], executable_path=path + headless=const.HEADLESS, args=['--start-maximized'], executable_path=path ) context = browser.new_context(no_viewport=True) context.add_cookies(parse_cookies(cookies)) @@ -558,7 +556,7 @@ def playwright_check_account_cookies(cookies): with sync_playwright() as playwright: update_windows_distinguish() browser = playwright.chromium.launch( - headless=HEADLESS, args=['--start-maximized'], executable_path=path + headless=const.HEADLESS, args=['--start-maximized'], executable_path=path ) context = browser.new_context(no_viewport=True) context.add_cookies(parse_cookies(cookies)) @@ -632,7 +630,7 @@ def playwright_login(username, password, code_2fa=None): with sync_playwright() as playwright: update_windows_distinguish() browser = playwright.chromium.launch( - headless=HEADLESS, args=['--start-maximized'], executable_path=path + headless=const.HEADLESS, args=['--start-maximized'], executable_path=path ) random_user_agent = UserAgent().getBrowser("Chrome").get("useragent") logger.info(f"使用ua={random_user_agent}") @@ -746,7 +744,7 @@ def playwright_m_login(username, password, code_2fa=None): with sync_playwright() as playwright: update_windows_distinguish() browser = playwright.chromium.launch( - headless=HEADLESS, args=['--start-maximized'], executable_path=path + headless=const.HEADLESS, args=['--start-maximized'], executable_path=path ) # random_user_agent = UserAgent().getBrowser(["Chrome Mobile iOS"]).get("useragent") random_user_agent = "Mozilla/5.0 (Linux; Android 12; Pixel 6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.41 Mobile Safari/537.36"