在 Windows 操作系统中使用 selenium Chrome Webdriver 且选项提示_for_download=False 时无法下载文件

问题描述 投票:0回答:1

webdriver 浏览器下载错误

我运行的代码

from selenium import webdriver  # pip install selenium
from webdriver_manager.chrome import ChromeDriverManager  # pip install webdriver-manager
 
o = webdriver.ChromeOptions()
o.add_experimental_option('prefs', {
  'download.default_directory'        : 'C:\mydownload', # change default directory for downloads
  'download.prompt_for_download'      : False, # to auto download the file
  'download.directory_upgrade'        : True,
  'plugins.always_open_pdf_externally': True # it will not show PDF directly in chrome
})
wd = webdriver.Chrome(ChromeDriverManager().install(), options=o)
wd.get('https://file-examples.com/wp-content/storage/2017/10/file-sample_150kB.pdf')
# wd.quit()  # omit this line to see the error in the webdriver's browser

代码可以在我同事的macbook笔记本电脑上运行;虽然在我的 Windows 笔记本电脑上失败了。

我应该怎样做才能让它运行成功?

python selenium-webdriver download webdriver auto
1个回答
0
投票

对于更复杂的配置管理,您可以考虑使用外部配置管理系统(例如 Consul、Etcd 或 AWS Systems Manager Parameter Store)并在应用程序启动期间读取这些配置。

总结

确保在 AWS ECS 任务定义中正确设置环境变量。

读取runtime.exs中的运行时环境变量。

谨慎使用编译时环境变量并考虑它们是否真的有必要。

利用 Application.get_env/3 并在必要时提供默认值。

考虑使用外部配置管理系统来管理复杂的配置。

通过遵循这些最佳实践,您应该能够解决在 AWS ECS 上部署 Elixir/Phoenix 应用程序时遇到的环境变量问题

© www.soinside.com 2019 - 2024. All rights reserved.