我目前正在尝试使用Selenium和Python启动具有特定chrome扩展名的google chrome。该脚本部分起作用,尽管浏览器启动后,谷歌浏览器几乎立即关闭,但谷歌浏览器检测到并启动了我希望添加的扩展名(错误代码:“ ... selenium.common.exceptions.SessionNotCreatedException:消息:未创建会话”)。在使用扩展程序启动chrome后,如何保持浏览器打开?该脚本不会在驱动程序启动后读取任何内容,“ driver = webdriver.Chrome(options = options,execute_path = r'C:/Webdriver/chromedriver.exe')”
代码:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
unpacked_extension_path = '/path/to/unpacked/extension/''
options = Options()
options.add_argument('--load-extension={}'.format(unpacked_extension_path))
driver = webdriver.Chrome(options=options, executable_path=r'C:/Webdriver/chromedriver.exe')
driver.get('example.com')
我尝试添加“ chrome_options.add_experimental_option(“ detach”,True)“和/或”全局驱动程序“。任何帮助将不胜感激!
屏幕截图: