OS X 10.8でpythonバインディングを使用してselenium webdriverでpdfをダウンロードしようとしています。
ダウンロードリンクが機能するかどうかを確認するだけでなく、実際にpdfファイルが必要です。私が理解しているように、デフォルトの「プレビュー」ではなく、pdfコンテンツタイプをダウンロードするようにFirefoxプロファイルを設定する必要があります。
Firefox のインスタンスを開くコードは次のとおりです。
def Engage():
print "Start Up FIREFOX"
## Create a new instance of the Firefox driver
profile = webdriver.firefox.firefox_profile.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.dir', os.path.expanduser("~/Documents/PYTHON/Download_Files/tmp/"))
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', ('application/pdf'))
driver = webdriver.Firefox(firefox_profile=profile)
return driver
また、最初にプロファイルを次のように設定しようとしました:
profile = webdriver.FirefoxProfile()
## replacing :: profile = webdriver.firefox.firefox_profile.FirefoxProfile()
## the other attributes remained
これは同じ結果になります
このプロファイルは、pdf をダウンロードするのではなく、新しいウィンドウでプレビュー モードで開きます。
リクエストを通じてコンテンツ タイプを再確認したところ、「application/pdf」として確認できました。
import requests
print requests.head('mywebsite.com').headers['content-type']
私が間違っていることについて何か考えはありますか?