【发布时间】:2022-12-21 02:16:17
【问题描述】:
我想使用选项以无头模式启动 Chrome 浏览器。 根据文档,我们需要导入选项,例如:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--headless')
driver = webdriver.Chrome(path/to/executable/file, chrome_options=options)
但是,我们如何在如下所述的类中传输选项?
class Browser(webdriver.Chrome):
def __init__(self):
self.driver_path = r"path/to/executable/file"
os.environ['PATH'] += os.pathsep + self.driver_path
super(Browser, self).__init__()
def some_function(self):
...
【问题讨论】:
-
super().__init__(path/to/executable/file, chrome_options=options)
标签: python class google-chrome selenium-webdriver headless-browser