I am having some trouble configuring Python Selenium Webdriver with FireFox to automatically download several PDFs that are linked in a table on a webpage. I'm looping through several pages so ideally I'd like to be able to save in a directory based on which page it is from and which line of the table it is from (i.e. \Download\PageX\FileX.pdf).
The links on the webpage do not go directly to the PDFs, they go to a page where just the PDF is embedded. A sample one looks like this:
<a class="PDFClass" target="_blank" href="?x=UKio-0xnvun6s3JHm7yAc--0ca8oK6ec7FQfkVyXvIDdM9jkF01rcqMb8un5SJxSB6OzgwLXiEVfhDr-dqCDjp9EReWU2KH927jg4GJ6EEbf53wL9Gdq6DUj9jFUrOhUKalBKL8pge5y5UlPt2VTVOXTrJUh4sF0ujPLhYKOct0" style="">Image</a>
I've configured my webdriver like this so far:
import os
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', os.getcwd())
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'pdf')
driver = webdriver.Firefox(profile)
I was under the impression that at the very least this configuration would automatically download a pdf when it is opened, but when I try doing a .click() on the element, it doesn't download. If I manually go into the browser settings and change the FireFox PDF preview to "save", then when I manually click the link or do a .click(), the file automatically downloads. Any guidance would be great!