python selenium清除缓存和cookies

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46529761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 17:40:50  来源:igfitidea点击:

python selenium clearing cache and cookies

pythonseleniumcachingcookies

提问by Tyrell

I'm trying to clear the cache and cookies in my firefox browser but I can't get it to work. I have searched it up and i'm only getting solutions for java and C#. How do I clear the cache and cookies in Python?

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

selenium version: 3.6.0

硒版本:3.6.0

platform: python

平台:python

python version: 2.7.8

蟒蛇版本:2.7.8

webdriver: geckodriver

网络驱动程序:geckodriver

browser platform: Firefox

浏览器平台:火狐

回答by Wojciech Kuczer

for cookies use 'delete_all_cookies()' function

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

driver.delete_all_cookies()

driver.delete_all_cookies()

for cache create profile

用于缓存创建配置文件

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)