慕碼人2483693
2023-06-27 16:30:39
我已經(jīng)嘗試了該網(wǎng)站上發(fā)布的一些解決方案,但我仍然無法使這個東西發(fā)揮作用。我必須從安全網(wǎng)站獲取 PDF。我能夠一直到達(dá)具有創(chuàng)建 PDF 按鈕的頁面,但我找不到可以讓我下載 PDF 的代碼。這是我到目前為止所得到的,非常感謝任何幫助! 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)
1 回答

ibeautiful
TA貢獻(xiàn)1993條經(jīng)驗(yàn) 獲得超6個贊
一旦您打開 PDF,Chromium/Google Chrome 很有可能會在基于 PDF.js 的查看器中打開該 PDF。為了解決這個問題并“下載”PDF,請嘗試ChromeOptions()在創(chuàng)建實(shí)例時傳遞具有以下配置文件屬性的實(shí)例Chrome(),如下所示:
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)
順便說一句,您始終可以使用該requests模塊。
添加回答
舉報(bào)
0/150
提交
取消