小编Vic*_*res的帖子

使用 Selenium/Python 下载嵌入式 PDF?

我已经尝试了该网站上发布的一些解决方案,但我仍然无法使这个东西发挥作用。我必须从安全网站获取 PDF。我能够一直到达具有创建 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)
Run Code Online (Sandbox Code Playgroud)

python pdf download selenium-chromedriver selenium-webdriver

3
推荐指数
1
解决办法
2353
查看次数