问题描述
我需要使用 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'}
- 尝试打开 URL 隐身模式,但我仍然必须打开 devtools 并手动禁用缓存
解决方法
driver.execute_cdp_cmd("Network.setCacheDisabled",{"cacheDisabled":True})
使用 chrome dev 协议,看看是否有帮助
https://chromedevtools.github.io/devtools-protocol/tot/Network/#method-setCacheDisabled