繁体   English   中英

如何在python中使用selenium下载pdf文件

[英]How to download pdf files using selenium in python

我试图使用selenium从网站下载pdf文件,但我能够打开文件,但它不能使用代码自动下载。

码:

chrome_profile = webdriver.ChromeOptions()
profile = {"download.default_directory": "C:\Users\Downloads",
   "download.prompt_for_download": False,
   "download.directory_upgrade": True,
   "plugins.plugins_disabled": ["Chrome PDF Viewer"]}
chrome_profile.add_experimental_option("prefs", profile)

请建议。 先感谢您

以上问题现在解决了

    prefs = {"plugins.always_open_pdf_externally": True}
    chromeOptions.add_experimental_option("prefs",prefs)
    chromedriver = "\path\chromedriver.exe"
    driver = webdriver.Chrome(executable_path=chromedriver, chrome_options=chromeOptions)

把它放在代码的个人资料部分,它会禁用chrome PDF查看器并触发自动下载

"plugins.plugins_disabled": ["Chrome PDF Viewer"]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM