我使用它來獲取驅動程序:
def get_browser(storage_dir, headless=False):
"""
Get the browser (a "driver").
Parameters
----------
storage_dir : str
headless : bool
Results
-------
browser : selenium webdriver object
"""
# find the path with 'which chromedriver'
path_to_chromedriver = '/usr/local/bin/chromedriver'
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
if headless:
chrome_options.add_argument("--headless")
chrome_options.add_experimental_option('prefs', {
"plugins.plugins_list": [{"enabled": False,
"name": "Chrome PDF Viewer"}],
"download": {
"prompt_for_download": False,
"default_directory": storage_dir,
"directory_upgrade": False,
"open_pdf_in_system_reader": False
}
})
browser = webdriver.Chrome(path_to_chromedriver,
chrome_options=chrome_options)
return browser
通過切換headless
參數,你可以看它與否。
哪個平臺? – Marcin 2012-03-19 19:16:03
爲什麼你需要一個無頭的Chrome實例? – 2012-03-19 19:26:25
@Marcin,我在Windows 7上開發,但將作爲Ubuntu上的網站發佈應用程序。 – Trindaz 2012-03-19 19:26:53