Ruby + Seleniumでfirefoxを使ってPDFファイルのダウンロードを行おうとしています.
その際,firefoxのprofileを設定しようとしているのですが,どうにもうまくいきません.
このサイトの以下のコードを実行しても,PDFファイルをダウンロードしてくれず,firefoxのbuilt-in PDF viewerでファイルが表示されてしまいます.
http://yizeng.me/2014/05/23/download-pdf-files-automatically-in-firefox-using-selenium-webdriver/
Ruby
1require 'selenium-webdriver' 2 3profile = Selenium::WebDriver::Firefox::Profile.new 4profile["browser.download.folderList"] = 2 5profile["browser.download.dir"] = 'C:\' 6profile["browser.helperApps.neverAsk.saveToDisk"] = 'application/pdf' 7 8profile["pdfjs.disabled"] = true 9 10profile["plugin.scan.plid.all"] = false 11profile["plugin.scan.Acrobat"] = "99.0" 12 13driver = Selenium::WebDriver.for :firefox, :profile => profile 14driver.get('http://static.mozilla.com/moco/en-US/pdf/mozilla_privacypolicy.pdf')
いろいろ試してみると,profileの設定が全く効いていないようなのです.
それで,firefoxのprofile managerで,PDFはファイルを表示せずに所定のフォルダにダウンロードするようにした,予めprofileを作っておき,以下のようにそれを読み込むようにするとちゃんとダウンロードしてくれました.
Ruby
1require 'selenium-webdriver' 2 3profile = Selenium::WebDriver::Firefox::Profile.from_name "hogehoge" 4profile.native_events = true 5 6driver = Selenium::WebDriver.for :firefox, :profile => profile 7driver.get('http://static.mozilla.com/moco/en-US/pdf/mozilla_privacypolicy.pdf')
firefoxのprofile関係の仕様が変わってしまったのが,原因なのでしょうか?この辺の事情に関して情報をお持ちの方はいませんか?
あなたの回答
tips
プレビュー