0

我编写了一个脚本来自动从网络下载文件,如下所示:

#Automatically download files to a given folder profile settings
#---------------------------------------------------------------
profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.dir'] = 'C:\Documents and Settings\My Documents\userdata\Rubydownloads'
profile['browser.download.folderList'] = 2
profile['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf,application/x-pdf,application/acrobat,application/vnd.pdf,text/pdf,text/x-pdf,image/jpeg,image/pjpeg,image/gif,image/bmp,image/x-windows-bmp,image/tif,image/x-tif,image/tiff,image/x-tiff,application/tif,application/x-tif,application/tiff,application/x-tiff"
profile['browser.download.manager.showWhenStarting'] = false
driver = Selenium::WebDriver.for :firefox, :profile => profile

但我的不好,一些.tif,.tiff and .pdf仍然错过而没有被下载。可以做到吗,比如说 - 如果mime type在上述配置文件设置中找不到合适的,那么脚本应该将其添加mime到浏览器设置中,以继续下载?

请在这里帮助我。

4

1 回答 1

0

我正在解决类似的问题。

我不确定您的neverAsk.saveToDisk列表中是否缺少 mime 类型(看起来不像),但我建议以下内容可能会有所帮助:

profile['browser.helperApps.alwaysAsk.force'] = 'false'
于 2013-09-06T16:16:09.590 回答