Python:如何让 Firefox 首选项自动下载 .eml 文件?

标签 python firefox selenium-webdriver preference eml

我正在尝试将 Firefox 浏览器上的首选项设置为在下载 .eml 文件时从不要​​求保存到磁盘(我希望 Firefox 自动下载 EML 文件)。

def setUp(self):
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', os.path.join(os.path.expanduser("~"), "Downloads\\"))
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'text/csv,message/rfc822')
self.driver = webdriver.Firefox(profile)
self.base_url = baseurl
self.verificationErrors = []
self.accept_next_alert = True
self.driver.implicitly_wait(3)  

使用此代码,我可以下载 .csv,而不会在 Firefox 中出现 saveToDisk 弹出窗口,但是,尽管设置了“message/rfc822”MIME 类型,但这不适用于 .eml。

任何人都可以帮助解释一下我是否缺少某些内容来下载 .eml 文件而不在 Firefox 中显示任何弹出窗口吗?

最佳答案

我遇到了同样的问题并用这个解决了它:

profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', os.getcwd())
profile.set_preference("browser.helperApps.neverAsk.saveToDisk","application/xml,text/plain,text/xml,image/jpeg,text/eml");        
driver = webdriver.Firefox(profile)

关于Python:如何让 Firefox 首选项自动下载 .eml 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42075194/

相关文章:

python - 如何使用 SQLAlchemy 使用 SELECT COUNT(*) 计算行数?

javascript - 检测 Firefox 扩展版本

javascript - DropzoneJS-索引大小错误: Index or size is negative or greater than the allowed amount

selenium-webdriver - Selenium 中的 EventFiringWebDriver 是什么?

python - 创建二进制 PBM/PGM/PPM

python - 如何在 Python 中使用 Pandas 创建一系列数字

python - 单击模块自动完成功能在 3 组深度下不起作用

ruby-on-rails - 关闭 Firefox 中文本字段的自动完成功能

java - 在我的 Junit 测试用例中,第一个测试失败后的所有测试

java - Webdriver 访问数据交换元素