【发布时间】:2021-02-18 00:28:39
【问题描述】:
我正在尝试从以下网址下载 PDF,https://sec.report/Document/0001670254-20-001152/
在 html 中嵌入了一个下载按钮。我正在使用以下代码单击按钮并将下载内容发送到我的路径中定义的桌面。程序运行没有任何错误,但 PDF 未显示在桌面上。我尝试将位置更改为不同的位置,即下载。我还切换了 google chrome 中的首选项以下载 PDF 文件,而不是在 Chrome 中自动打开它们。有什么想法吗?
from selenium import webdriver
download_dir = "C:\\Users\\andrewlittle\\Desktop"
options = webdriver.ChromeOptions()
profile = {"plugins.plugins_list": [{"enabled": False, "name": "Chrome PDF Viewer"}],
"download.default_directory": download_dir , "download.extensions_to_open": "applications/pdf"}
options.add_experimental_option("prefs", profile)
chromedriver_path = os.getcwd() + '/chromedriver'
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://sec.report/Document/0001670254-20-001152/document_1.pdf')
driver.close()
提前致谢!
【问题讨论】:
标签: python pdf path selenium-chromedriver