我使用selenium webdriver自动下载几个PDF文件.我得到了PDF预览窗口(见下文),现在我想下载该文件.如何使用Google Chrome浏览器来完成此操作?
解决方法:
您可以使用selenium从网上下载pdf(Embeded pdf& normal pdf).
from selenium import webdriver
download_dir = "C:\\Users\\omprakashpk\\Documents" # for linux/*nix, download_dir="/usr/Public"
options = webdriver.ChromeOptions()
profile = {"plugins.plugins_list": [{"enabled": False, "name": "Chrome PDF Viewer"}], # disable Chrome's PDF Viewer
"download.default_directory": download_dir , "download.extensions_to_open": "applications/pdf"}
options.add_experimental_option("prefs", profile)
driver = webdriver.Chrome('C:\\chromedriver\\chromedriver_2_32.exe', chrome_options=options) # Optional argument, if not specified will search path.
driver.get(`pdf_url`)
它将下载并保存指定目录中的pdf.根据您的方便更改download_dir位置和Chrome驱动程序位置.
您可以从here下载chrome驱动程序.
希望能帮助到你!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。