Python Selenium清除缓存和Cookies

27

我正在尝试清除火狐浏览器中的缓存和cookie,但是我无法使其工作。我已经搜索了相关解决方案,但只找到了针对Java和C#的解决方案。请问如何在Python中清除缓存和cookie?

selenium版本:3.6.0

平台:Python

Python版本:2.7.8

webdriver:geckodriver

浏览器平台:Firefox


关闭webdriver并重新打开 - Dalvenjia
1个回答

59

对于Cookies,请使用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)

2
有没有办法在不创建新的 Web Driver 实例的情况下清除 cookies? - Jenya Pu

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接