我的目标是使用Chrome作为一项服务,以在屏幕上显示全屏网页。 我通过创建一个使用Selenium将chrome定向到正确页面并正确设置网站格式的python脚本来解决这一难题。由于主要的要求是显示,因此所显示的网页必须畅通无阻。在我的实例中有两个障碍可以通过使用不同的excludeSwitches选项来解决:
要禁用自动化栏:
chrome_options.add_experimental_option("excludeSwitches",['enable-automation']);
要禁用“禁用开发人员模式扩展”弹出窗口,请执行以下操作:
chrome_options.add_experimental_option("excludeSwitches",['load-extension'])
但是我还没有找到一种同时实现这两种方法的方法-我尝试过:
chrome_options.add_experimental_option("prefs",{"excludeSwitches": ['enable-automation'],"excludeSwitches": ['load-extension']});
prefs = {"excludeSwitches": ['enable-automation,load-extension'],"excludeSwitches": ['load-extension','enable-automation']}
chrome_options.add_experimental_option("prefs",prefs);
在这些情况下,取决于顺序,其中只有一种具有预期的效果。如何正确使用这两个选项?
测试代码(不包括进口商品):
chrome_options = webdriver.ChromeOptions();
chrome_options.add_experimental_option("prefs",{"excludeSwitches": ['enable-automation','load-extension']})
browser = webdriver.Chrome(chrome_options=chrome_options)
browser.get(('https://www.google.co.uk'))