Python、Selenium、下载所有 MIME 类型

标签 python firefox selenium selenium-webdriver

我正在尝试使用 Firefox 的 selenium webdriver 下载一些文件。 如何为任何 MIME 类型设置选项 browser.helperApps.neverAsk

现在此选项仅适用于 application/pdf (在我的脚本中):

#selenium profile
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.dir', download_dir)
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/pdf')
#-------------------
driver = webdriver.Firefox(firefox_profile=profile)

最佳答案

您必须明确列出 mimetype 并用逗号分隔值:

profile.set_preference('browser.helperApps.neverAsk.saveToDisk',
                       'application/pdf,text/csv')

关于Python、Selenium、下载所有 MIME 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27357152/

相关文章:

java - 如何在 Selenium 中启用 PhantomJS WebDriver?

python - 不小心在 shell 脚本中使用了 mv 并移动了文件。 shell脚本在mac上默认运行在哪里?

python - 使用 Cython 为困难的 C 头文件编写 Python 包装器

java - 如何使用selenium webdriver从java生成Har文件而不自动导出?

css - 辅助功能 : Prevent browser from overriding CSS in input fields

firefox - 从命令行在 Firefox 上安装 WebExtensions

python - Selenium 蟒 : How to click on a <a> tag based on "onclick" text

python - 仅将文本附加到非空值 pandas Dataframe

python - 如何获取li标签内的链接?

wordpress - 我的网站标题在 Chrome 和 Firefox 上的行为不同?