如何从Python Selenium ChromeDriver中保存在Chrome中打开的嵌入式PDF

ChromeDriver for Selenium能够在登录后打开嵌入式PDF,但是如何将chrome文件中的PDF文件保存到本地磁盘?谢谢.
最佳答案
def download_pdf(lnk):
    options = webdriver.ChromeOptions()
    tgt = tempfile.mkdtemp()
    profile = {"plugins.plugins_list": [{"enabled":False,"name":"Chrome PDF Viewer"}],
        "download.default_directory" : tgt}
    options.add_experimental_option("prefs",profile)
    driver = webdriver.Chrome(CHROMEDRIVER, chrome_options = options)
    driver.get(lnk)
    driver.find_element_by_id('userName1').send_keys('username')
    driver.find_element_by_id('password1').send_keys('password')
    driver.find_element_by_id('loginButton1').click()

    ftgt = os.path.join(tgt,'downloaed.pdf')
    while not os.path.exists(ftgt):
        time.sleep(3)
    driver.close()
    return ftgt

转载注明原文:如何从Python Selenium ChromeDriver中保存在Chrome中打开的嵌入式PDF - 代码日志