問題描述
我整天都在尋找這個,似乎目前沒有可用的解決方案可從 python 的 chromedriver 實現中獲得.
I have been searching all day for this and it seems that there is no solution currently available from the chromedriver implementation for python.
如何使用 webdriver.Chrome() 方法設置特定的 chrome.prefs(例如 profile.managed_default_content_settings.images = 2 等配置文件設置)?
how do you set specific chrome.prefs (for example profile settings such as profile.managed_default_content_settings.images = 2) using the webdriver.Chrome() method?
我已經通過 webdriver.ChromeOptions() 嘗試過,但沒有成功.在 Java 中,有適當的函數可以實現這一點.
I already tried it through webdriver.ChromeOptions() without success. In Java there are appropriate functions available to achieve this.
但是 Python 呢?這就是我目前正在做的事情......
But Python? This is what I am doing currently...
options = webdriver.ChromeOptions()
options.add_argument('--allow-running-insecure-content')
options.add_argument('--disable-web-security')
options.add_argument('--disk-cache-dir=/var/www/cake2.2.4/app/tmp/cache/selenium-chrome-cache')
options.add_argument('--no-referrers')
options.add_argument('--window-size=1003,719')
options.add_argument('--proxy-server=localhost:8118')
options.add_argument("'chrome.prefs': {'profile.managed_default_content_settings.images': 2}")
self.selenium = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver',chrome_options=options)
推薦答案
對于任何想在 chromedriver 中禁用圖像的人,以下代碼可能會對您有所幫助.
For anyone who want to disable images in chromedriver, the following code might help you.
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option( "prefs", {'profile.default_content_settings.images': 2})
driver = webdriver.Chrome(chrome_options=chrome_options)
這篇關于在 chromedriver 中使用 python 綁定為 selenium 設置 chrome.prefs的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!