【问题标题】:How do I bypass the "harmful file" download warning on chrome with selenium?如何绕过带有硒的 chrome 上的“有害文件”下载警告?
【发布时间】:2022-09-30 05:38:29
【问题描述】:

我正在使用 python/selenium 从数百个 IP 设备下载多个配置文件。如何绕过此警告并自动下载这些文件?

"This type of file may be harmful to your computer" Keep/Discard"

【问题讨论】:

    标签: python selenium google-chrome selenium-webdriver selenium-chromedriver


    【解决方案1】:

    您可以使用 chrome_options 更改 Chrome 的默认下载设置:

    from selenium import webdriver
    
    chrome_options = webdriver.ChromeOptions()
    prefs = {}
    prefs["download.prompt_for_download"] = False
    prefs["download.directory_upgrade"] = True
    prefs["default_content_setting_values.notifications"] = 0
    prefs["content_settings.exceptions.automatic_downloads.*.setting"] = 1
    prefs["safebrowsing.disable_download_protection"] = True
    prefs["default_content_settings.popups"] = 0
    prefs["managed_default_content_settings.popups"] = 0
    prefs["profile.password_manager_enabled"] = False
    prefs["profile.default_content_setting_values.notifications"] = 2
    prefs["profile.default_content_settings.popups"] = 0
    prefs["profile.managed_default_content_settings.popups"] = 0
    prefs["profile.default_content_setting_values.automatic_downloads"] = 1
    chrome_options.add_experimental_option("prefs", prefs)
    
    driver = webdriver.Chrome(options=chrome_options)
    

    或者您可以使用默认情况下已经具有这些设置的 Selenium Python 框架:https://github.com/seleniumbase/SeleniumBase

    【讨论】:

      猜你喜欢
      • 2012-03-19
      • 2014-08-18
      • 1970-01-01
      • 2021-10-02
      • 1970-01-01
      • 1970-01-01
      • 2017-04-29
      • 2013-11-04
      • 2021-03-13
      相关资源
      最近更新 更多