【发布时间】:2021-04-03 19:11:41
【问题描述】:
当我使用 selenium 网络驱动程序打开一个 url 并希望将文件下载到特定文件夹时。我尝试了下面的代码,但没有工作。
options = Options()
options.add_argument("--disable-extensions")
options.add_argument("--disable-infobars")
options.add_argument("--headless")
# etc...
# declare prefs
prefs = {"media.autoplay.enabled": False, "network.proxy.autoconfig_url": pac_url,
"network.proxy.autoconfig_url.include_path": True}
# add prefs
chromeOptions.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(executable_path="chromdriver85/chromedriver.exe", chrome_options=options)
任何更好的标准解决方案。谢谢你
【问题讨论】:
-
您要询问哪些文件?
-
你试过设置这个 -->
prefs = {"download.default_directory" : "/some/path"}? -
@vitaliis,需要自动下载到指定文件夹。
-
@Dev,我在 chromeOptions.add_experimental_option("prefs", prefs) 处遇到错误。错误是 chromeOptions 不可用。
标签: python-3.x selenium selenium-webdriver selenium-chromedriver