赞
踩
我正在尝试使用chrome首选项禁用图像加载。 这是我的代码:
from selenium.webdriver import Remote
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--allow-running-insecure-content')
prefs = {"profile.managed_default_content_settings.images": 2}
chrome_options.add_experimental_option("prefs",prefs)
# Note: '127.0.0.1:8888 is my Charles proxy.
chrome_options.add_argument('--proxy-server=http://127.0.0.1:8888')
driver = Remote(
command_executor='http://127.0.0.1:4444/wd/hub',
desired_capabilities=chrome_options.to_capabilities())
driver.get('https://www.google.com')
我期待驱动程序加载网站上没有图像。 但它确实(从我在查尔斯看到的)。
在容器中,我可以找到带有路径/tmp/.org.chromium.Chromium.xxxxxx/Default/Preferences的首选项文件:
{"alternate_error_pages":{"enabled":false},"autofill":{"enabled":false},"browser":{"check_default_browser":false},"distribution":{"import_bookmarks":false,"import_history":false,"import_search_engine":false,"make_chrome_default_for_user":false,"skip_first_run_ui":true},"dns_prefetching":{"enabled":false},"profile":{"content_settings":{"pattern_pairs":{"https://*,*":{"media-stream":{"audio":"Default","video":"Default"}}}},"default_content_setting_values":{"geolocation":1},"default_content_settings":{"geolocation":1,"mouselock":1,"notifications":1,"popups":1,"ppapi-broker":1},"managed_default_content_settings":{"images":2},"password_manager_enabled":false},"safebrowsing":{"enabled":false},"search":{"suggest_enabled":false},"translate":{"enabled":false}}
对我来说,experiment_option不起作用,因为浏览器没有正确读取Preferences文件
有任何想法吗?
我正在使用最新的docker image selenium / standalone-chrome,并按照文档中的建议运行图像
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。