切记用逗号分隔插件路径,不能有空格
f"–disable-extensions-except={cookie_extension},{path_to_extension}“,
f”–load-extension={path_to_extension},{cookie_extension}"
from getpass import getuser
import time
from playwright.sync_api import sync_playwright
import requests
# 不出意外这个可以获取到你google的本地缓存文件
__USER_DATE_DIR_PATH__ = f"C:\\Users\\{getuser()}\\AppData\Local\Google\Chrome\\User Data"
# chrome.exe 的地址
__EXECUTABLE_PATH__ = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
path_to_extension = r'E:\chrome_extension\omega_switch\2.5.21_0'
cookie_extension = r'E:\chrome插件\EditThisCookie'
playwright = sync_playwright().start()
browser = playwright.chromium.launch_persistent_context(
# 指定本机用户缓存地址
user_data_dir=__USER_DATE_DIR_PATH__,
# 指定本机google客户端exe的路径
executable_path=__EXECUTABLE_PATH__,
# 要想通过这个下载文件这个必然要开 默认是False
accept_downloads=True,
# 设置不是无头模式
headless=False,
bypass_csp=True,
slow_mo=10,
# 跳过检测
args=['--disable-blink-features=AutomationControlled',
# f"--disable-extensions-except= {cookie_extension}",
f"--disable-extensions-except={cookie_extension},{path_to_extension}",
f"--load-extension={path_to_extension},{cookie_extension}"
]
)
page = browser.new_page()
参考
https://blog.csdn.net/weixin_59938810/article/details/124350045