【发布时间】: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
我正在使用 python/selenium 从数百个 IP 设备下载多个配置文件。如何绕过此警告并自动下载这些文件?
"This type of file may be harmful to your computer" Keep/Discard"
【问题讨论】:
标签: python selenium google-chrome selenium-webdriver selenium-chromedriver
您可以使用 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
【讨论】: