赞
踩
Preferences for ChromeDriver是一个实验性的选项。
可以显式设置下载首选项。
from selenium import webdriver options = webdriver.ChromeOptions() prefs = { "download.open_pdf_in_system_reader": False, "download.prompt_for_download": True, "plugins.always_open_pdf_externally": False } options.add_experimental_option( "prefs", prefs ) driver = webdriver.Chrome( options=options ) driver.get( "https://www.hudoig.gov/sites/default/files/documents/2016-FW-1007.pdf" ) driver.close()
或者,可以将下载位置设置为将文档作为/dev/null写入虚拟设备文件,从而有效地将其丢弃。
prefs = {
"download.open_pdf_in_system_reader": False,
"download.prompt_for_download": True,
"download.default_directory": "/dev/null",
"plugins.always_open_pdf_externally": False
}
options.add_experimental_option(
"prefs", prefs
)
或者可以将下载限制设置为block all downloads。
prefs = {
"download_restrictions": 3,
}
options.add_experimental_option(
"prefs", prefs
)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。