Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Selenium Python中为Chrome设置首选项_Python_Selenium_Google Chrome - Fatal编程技术网

如何在Selenium Python中为Chrome设置首选项

如何在Selenium Python中为Chrome设置首选项,python,selenium,google-chrome,Python,Selenium,Google Chrome,我可以如下设置Firefox的首选项 set_preference = profile.set_preference set_preference("network.http.response.timeout", 30) set_preference("media.autoplay.enabled", False) set_preference("browser.cache.memory.enable", False) set_preference("browser.cache.disk.ena

我可以如下设置Firefox的首选项

set_preference = profile.set_preference
set_preference("network.http.response.timeout", 30)
set_preference("media.autoplay.enabled", False)
set_preference("browser.cache.memory.enable", False)
set_preference("browser.cache.disk.enable", False)
set_preference("network.proxy.type", 2)
set_preference("network.proxy.autoconfig_url", pac_url)
set_preference("network.proxy.autoconfig_url.include_path", True)
但我也需要为Chrome设置。。谁能帮我怎么办


感谢Hafsa。

对于Chrome,我想您正在这里寻找
ChromeOptions
。您可以将
prefs
添加到
ChromeOptions

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

# options
options = Options()
options.add_argument("--disable-extensions")
options.add_argument("--disable-infobars")
options.add_argument("--headless")
# etc...

# declare prefs
prefs = {"media.autoplay.enabled" : False, "network.proxy.autoconfig_url" : pac_url, "network.proxy.autoconfig_url.include_path" : True}

# add prefs 
chromeOptions.add_experimental_option("prefs", prefs)


driver = webdriver.Chrome(chrome_options=options)