【问题标题】:How to store files into a folder in selenium python如何将文件存储到 selenium python 中的文件夹中
【发布时间】: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


【解决方案1】:

您可以将文件下载到默认文件夹,然后将它们复制或移动到所需的文件夹。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-17
    • 2012-02-05
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    • 2021-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多