【问题标题】:Selenium firefox profile download directory preference not getting implementedSelenium firefox 配置文件下载目录首选项未实现
【发布时间】:2021-12-22 14:20:15
【问题描述】:

我有以下代码

profile = webdriver.FirefoxProfile()
    profile.set_preference("browser.download.folderList", 2)
    profile.set_preference("browser.download.manager.showWhenStarting", False)
    profile.set_preference("browser.download.dir", os.path.dirname(os.path.realpath(__file__)))
    profile.set_preference("browser.helperApps.neverAsk.openFile", "application/zip")
    driver = webdriver.Firefox(firefox_profile=profile)

但是当 zip 文件被下载时,它仍然会被下载到我的临时目录中。

这里的任何帮助将不胜感激!

【问题讨论】:

  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: python selenium selenium-webdriver selenium-firefoxdriver firefox-profile


【解决方案1】:

你需要做如下两个小修改:

os.path.dirname(os.path.realpath(__file__))

与:

os.path.abspath(os.path.dirname(__file__))

后跟一行:

profile.set_preference("browser.download.folderList", 2)

实际上,您的代码块将是:

profile = webdriver.FirefoxProfile()
    profile.set_preference("browser.download.dir", os.path.abspath(os.path.dirname(__file__)))
    profile.set_preference("browser.download.folderList", 2)
    profile.set_preference("browser.download.manager.showWhenStarting", False)
    profile.set_preference("browser.helperApps.neverAsk.openFile", "application/zip")
    driver = webdriver.Firefox(firefox_profile=profile)

参考文献

您可以在what does the file variable mean/do?

找到关于os.path.abspath(os.path.dirname(__file__))的详细讨论

【讨论】:

  • 它仍在下载到临时目录中,我通过将文件移出临时目录解决了这个问题,但这并不是一个可靠的解决方法,因为它正在下载的文件可能会更改名称
猜你喜欢
  • 2023-04-04
  • 2017-05-29
  • 2012-05-09
  • 2018-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-04
相关资源
最近更新 更多