在Chrome / Firefox的网络驱动程序中停用Cookie [英] Disabling Cookies in Webdriver for Chrome/Firefox

查看:194
本文介绍了在Chrome / Firefox的网络驱动程序中停用Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试在Chrome或Firefox浏览器启动时停用所有Cookie。我已经看到了这里的例子,但他们都在Java,一些Selenium代码是不同于Python。

I am trying to disable all cookies when starting up either the Chrome or Firefox browser. I have seen the examples on here but they're all in Java, and some of the Selenium code is different than it is for Python.

ChromeOptions options = new ChromeOptions();  
Map prefs = new HashMap();  
prefs.put("profile.default_content_settings.cookies", 2);  
options.setExperimentalOptions("prefs", prefs); 
driver = new ChromeDriver(options);  

我想在Python中执行上述操作。

I want to do the above, just in Python.

推荐答案

这将是:

from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("prefs", {"profile.default_content_settings.cookies": 2})

driver = webdriver.Chrome(chrome_options=chrome_options)

测试 - 适用于我(Chrome 45,selenium 2.47)。

tested - worked for me (Chrome 45, selenium 2.47).

这篇关于在Chrome / Firefox的网络驱动程序中停用Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆