首页 > 解决方案 > 使用 python selenium 禁用网络选项卡上的缓存(自动化)

问题描述

我需要使用 selenium python 禁用网络选项卡上的缓存。尝试了以下方法,但没有任何效果

   options = webdriver.ChromeOptions()
            options.add_argument("--incognito")
            options.add_argument('--disable-application-cache')
            options.add_argument("--disk-cache-size=0")
            options.add_argument("--disk-cache-dir=/dev/null")
            options.add_argument("--disable-gpu")
            d = DesiredCapabilities.CHROME
            d['goog:loggingPrefs'] = {'browser': 'ALL'}

标签: pythonseleniumgoogle-chrome-devtools

解决方案


driver.execute_cdp_cmd("Network.setCacheDisabled", {"cacheDisabled":True})

使用 chrome dev 协议,看看这是否有帮助

https://chromedevtools.github.io/devtools-protocol/tot/Network/#method-setCacheDisabled


推荐阅读