Files
37duAutomation/plugins/XQ0001-0100/XQ0042 抖音平台核对/data/browser.py
T

38 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""浏览器:一次运行共用一个可见浏览器(登录 + 后续取数都复用它,避免反复开关)。
独立固定用户目录 %LOCALAPPDATA%\\37duAutomation\\browser_sessions\\xq0042,
不占用用户日常 Chrome 配置。注意:来客票据是会话级 Cookie,Chromium 退出后不保证保留,
所以登录态以 douyin_login 落盘的快照为准,启动后由 douyin_login.restore_cookies 注入。
"""
import os
from DrissionPage import ChromiumPage, ChromiumOptions
from .. import config
def open_page():
co = ChromiumOptions()
if config.HEADLESS:
co.headless()
co.set_argument('--start-maximized')
co.set_pref('credentials_enable_service', False)
co.set_pref('profile.password_manager_enabled', False)
profile = config.get_browser_profile_dir()
os.makedirs(profile, exist_ok=True)
co.set_user_data_path(profile)
config.log(f'浏览器用户目录:{profile}', 'DEBUG')
page = ChromiumPage(co)
if not config.HEADLESS:
# 登录要人工操作(账密/短信/扫码/滑块),全屏 + 置顶避免被其它窗口挡住
config.apply_window_mode(page)
return page
def close_page(page):
try:
page.quit()
except Exception:
pass