You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

selenium-python调用Firefox时无法覆盖xlsx文件下载保存选项如何解决

Selenium控制Firefox下载xlsx文件跳过确认弹窗配置说明

原始配置代码

以下是最初调用Firefox从网站下载xlsx文件时使用的代码:

from selenium import webdriver

options=webdriver.FirefoxOptions()
dest_dir = "myDir"

print (options.preferences)
#options.set_preference('profile', profile_path)
#options.set_preference("browser.download.useDownloadDir",True)
options.set_preference("browser.download.folderList",2)
options.set_preference("browser.download.dir",dest_dir)
options.set_preference("browser.download.manager.showWhenStarting",False)
options.set_preference("browser.helperApps.neverAsk.saveToDisk","application/xlsx/xls")
print (options.preferences)

driver = webdriver.Firefox(options=options)

遇到的问题

即便配置了上述参数,每次启动Firefox下载xlsx文件时仍会弹出下载确认询问:
下载提示截图

问题解决

问题根源是配置中填写的xlsx/xls文件MIME类型错误,将browser.helperApps.neverAsk.saveToDisk对应的参数值替换为正确的MIME类型即可:

options.set_preference("browser.helperApps.neverAsk.saveToDisk","application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")

其中application/vnd.ms-excel对应xls格式,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet对应xlsx格式。


内容的提问来源于stack exchange,提问作者Raj Kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 10:15:07