【问题标题】:selenium chrome driver without cache没有缓存的硒铬驱动程序
【发布时间】:2018-03-29 04:45:27
【问题描述】:

也许有人知道如何在不使用浏览器缓存的情况下在 Chrome 中冲浪? 我在循环中运行以隐身模式获取页面并且不关闭浏览器。但是好像使用了缓存,因为浏览器没有关闭。

chrome_options.add_argument("--incognito")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-java")

driver = webdriver.Chrome(chrome_options=chrome_options)
i = 1
while i < 10:
    driver.get('https://selenium.com') 
browser.quit()

【问题讨论】:

标签: javascript python google-chrome selenium caching


【解决方案1】:

每次导航到不同的页面时,您都应该尝试使用以下内容。

driver.manage().deleteAllCookies();

或者您可以简单地浏览到 chrome 本身的缓存页面,然后通过 selenium 单击“清除浏览数据”按钮。

chrome://settings/clearBrowserData

【讨论】:

  • 嗨!是否也只删除 cookie 或缓存?
  • 我不太确定,您可能想自己检查一下。您可以浏览到 chrome 清除缓存页面并使用 selenium 单击“清除浏览数据”。我已经更新了我的答案。
【解决方案2】:

您也可以使用 Chrome--disable-application-cache 参数,相当于“私人模式”

【讨论】:

    【解决方案3】:

    我知道该帖子已过时,但对于那些在 2020 年正在寻找可以通过 BrowserMob(BrowserUP) 代理本身实现的解决方案(所有浏览器,而不仅仅是 chrome)的人 - 您可以为请求和响应设置规则将删除与浏览器中的缓存机制相关的标头(有很多)。以下是我使用的脚本(它们可能不完整,如果您发现缺少的内容,请告知):

    请求:

    curl --location --request POST 'your_proxy_api_host:your_proxy_api_port/proxy/your_proxy_port/filter/request' \
    --header 'Content-Type: text/plain' \
    --data-raw 'request.headers().remove('\''If-Modified-Since'\'');request.headers().remove('\''If-None-Match'\'');'
    

    回复:

    curl --location --request POST '0.0.0.0:8080/proxy/8081/filter/response' \
    --header 'Content-Type: text/plain' \
    --data-raw 'response.headers().remove('\''Age'\'');response.headers().remove('\''ETag'\'');response.headers().remove('\''Cache-Control'\'');response.headers().remove('\''Expires'\'');response.headers().remove('\''Last-Modified'\'');response.headers().remove('\''Vary'\'');response.headers().add('\''Expires'\'', 0);response.headers().add('\''Cache-Control'\'', '\''private'\'');response.headers().add('\''Cache-Control'\'', '\''no-cache'\'');response.headers().add('\''Cache-Control'\'', '\''no-store'\'');response.headers().add('\''Cache-Control'\'', '\''must-revalidate'\'');response.headers().add('\''Vary'\'', '\''*'\'');'
    

    我使用 http 1.1,所以我没有为 http 1.0 或 http 2.0 添加任何内容。检查 Chrome Edge Safari FF。 另外,我使用小代理 api(browsermob 的新 api) - 用于reference

    【讨论】:

      猜你喜欢
      • 2011-11-19
      • 2017-03-20
      • 2018-05-03
      • 2019-02-14
      • 1970-01-01
      • 2021-05-14
      • 1970-01-01
      • 2015-09-21
      • 1970-01-01
      相关资源
      最近更新 更多