Selenium Webdriver:如何使用 Python 下载 PDF 文件? [英] Selenium Webdriver: How to Download a PDF File with Python?

查看:58
本文介绍了Selenium Webdriver:如何使用 Python 下载 PDF 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 selenium webdriver 自动下载多个 PDF 文件.我得到了 PDF 预览窗口(见下文),现在我想下载该文件.如何使用 Google Chrome 作为浏览器完成此操作?

I am using selenium webdriver to automate downloading several PDF files. I get the PDF preview window (see below), and now I would like to download the file. How can I accomplish this using Google Chrome as the browser?

推荐答案

试试这个代码,它对我有用.

Try this code, it worked for me.

options = webdriver.ChromeOptions()
options.add_experimental_option('prefs', {
"download.default_directory": "C:/Users/XXXX/Desktop", #Change default directory for downloads
"download.prompt_for_download": False, #To auto download the file
"download.directory_upgrade": True,
"plugins.always_open_pdf_externally": True #It will not show PDF directly in chrome
})
self.driver = webdriver.Chrome(options=options

这篇关于Selenium Webdriver:如何使用 Python 下载 PDF 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆