I've tried some of the solutions posted at this site but I still cannot make this thing work. I have to grab a PDF from a secured website. I'm able to get all the way to the page that has the button to create the PDF but I cannot find code that will let me then download the PDF. Here's what I got so far and any help is much appreciated!
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://service.medical.barco.com/server/jsp/login")
username = driver.find_element_by_name('j_username')
password = driver.find_element_by_name('j_password')
username.send_keys("XXX")
password.send_keys("XXX")
driver.find_element_by_css_selector('[value="Log on"]').click()
##makes the PDF and shows it in the Google PDF viewer
url = "https://service.medical.barco.com/server/spring/jsp/workstation/complianceCheckDetailReport/?displayId=932610524&date=1598328417477"
driver.get(url)
driver.find_element_by_class_name('href-button').click()
##This is probably unnecessary but I thought a direct link to the created PDF could give me a variable I could then download
pdf = "https://service.medical.barco.com/server/spring/jsp/workstation/complianceCheckDetailReport/jasper/report.pdf?format=pdf&displayId=932610524&date=1598328417477"
driver.get(pdf)
Once you get to the PDF, there are high chances that Chromium/Google Chrome will open the same in its PDF.js-based viewer. In order to get around this and 'download' the PDF, try passing an instance of ChromeOptions() with the following profile properties while creating a Chrome() instance as shown:
profile = {
'download.prompt_for_download': False,
'download.default_directory': '/path/to/download/the/pdf',
'download.directory_upgrade': True,
'plugins.always_open_pdf_externally': True,
}
options = webdriver.ChromeOptions()
options.add_experimental_option('prefs', profile)
driver = webdriver.Chrome(options=options)
On a side-note, you can always use the requests module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With