python selenium清除缓存和cookie

标签 python selenium caching cookies

我正在尝试清除我的 firefox 浏览器中的缓存和 cookie,但我无法让它工作。我已经搜索过了,我只得到了 java 和 C# 的解决方案。如何在 Python 中清除缓存和 cookie?

Selenium 版本:3.6.0

平台:python

python 版本:2.7.8

网络驱动程序:壁虎驱动程序

浏览器平台:Firefox

最佳答案

对于 cookie 使用 'delete_all_cookies()' 函数

driver.delete_all_cookies()

用于缓存创建配置文件

profile = webdriver.FirefoxProfile()
profile.set_preference("browser.cache.disk.enable", False)
profile.set_preference("browser.cache.memory.enable", False)
profile.set_preference("browser.cache.offline.enable", False)
profile.set_preference("network.http.use-cache", False) 
driver =webdriver.Firefox(profile)

关于python selenium清除缓存和cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46529761/

相关文章:

java - 在 Selenium 测试中指定自定义屏幕分辨率

c# Selenium WebDriver - 如何禁用 Facebook 页面上的通知?

PHP 响应缓存 : file vs MySQL

Python 剧作家无法访问元素

Python 3.4+ : Extending pathlib. 路径

python - GitPython 检查 git pull 是否更改了本地文件

python - TensorFlow 类型错误 : 'BatchDataset' object is not iterable/TypeError: 'CacheDataset' object is not subscriptable

c# - 如何在 Selenium 中获取和设置文本编辑器值

java - 使用单例模式在 Java 中进行缓存

.htaccess - 强制浏览器忘记缓存的重定向?