我有问题,我正在尝试为我的网络抓取工具配置自动保存 我正在使用Capybara + Selenium + Ruby + Firefox。请看下面的代码:
Capybara.register_driver :selenium do |app|
profile = Selenium::WebDriver::Firefox::Profile.new
profile['browser.download.folderList'] = 2
profile['browser.download.dir'] = "~/Downloads"
profile['browser.helperApps.alwaysAsk.force'] = false
profile['browser.download.manager.showWhenStarting'] = false
profile['browser.helperApps.neverAsk.openFile'] = "application/x-pdf,
application/acrobat, applications/vnd.pdf, text/pdf, text/x-pdf,
application/vnd.cups-pdf"
profile['browser.helperApps.neverAsk.saveToDisk'] = "application/x-pdf,
application/acrobat, applications/vnd.pdf, text/pdf, text/x-pdf,
application/vnd.cups-pdf"
profile["pdfjs.disabled"] = true
profile["browser.download.useDownloadDir"] = true
profile["plugin.scan.plid.all"] = false
profile["plugin.scan.Acrobat"] = "99.0"
profile.native_events = true
options = Selenium::WebDriver::Firefox::Options.new(profile: profile)
Capybara::Selenium::Driver.new(app, browser: :firefox, options: options)
end
Capybara.javascript_driver = :firefox
Capybara.configure do |config|
config.default_max_wait_time = 1000000
config.default_driver = :selenium
end
但它似乎不起作用
救救我!非常感谢你!
答案 0 :(得分:0)
很难说,因为您没有显示您是如何创建应用中使用的实际会话,但是您正在将javascript_driver设置为:firefox,同时在名为selenium的驱动程序中配置配置文件。如果您在会话中实际使用javascript_driver
(:firefox),则不会使用该配置文件。
此外,将browser.helperApps.neverAsk.openFile
和browser.helperApps.neverAsk.saveToDisk
设置为相同的MIME类似似乎是相互冲突的选项。