答案 0 :(得分:0)
您应将Selenium profile设置为启用下载而无需询问:
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream')
profile.set_preference("browser.safebrowsing.enabled", 'false')
driver = webdriver.Firefox(profile)
driver.get("http://yourpage.com")
"application/octet-stream"
是文件类型,如果您不知道文件类型,请检查MIME types
使用chrome,您应该可以使用:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_experimental_option("prefs", {
"download.default_directory": r"C:\Users\xxx\downloads\Test", # Insert the path where you want your files to be saved!
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"safebrowsing.enabled": True
})
driver = webdriver.Chrome(chrome_options=chrome_options)
还请this answer以获取更多信息