Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
既然我已经在Python中设置了保存,为什么Selenium仍然要求我配置保存?_Python_Selenium - Fatal编程技术网

既然我已经在Python中设置了保存,为什么Selenium仍然要求我配置保存?

既然我已经在Python中设置了保存,为什么Selenium仍然要求我配置保存?,python,selenium,Python,Selenium,我不是一个真正的Python用户,但我正在使用一些在线下载的代码来下载一个文件。其中一项守则是: urlpage = 'https://www150.statcan.gc.ca/n1/tbl/csv/' + '10100127' + '-eng.zip' profile = webdriver.FirefoxProfile() profile.set_preference("browser.download.folderList", 2)

我不是一个真正的Python用户,但我正在使用一些在线下载的代码来下载一个文件。其中一项守则是:

        urlpage = 'https://www150.statcan.gc.ca/n1/tbl/csv/' + '10100127' + '-eng.zip'
        profile = webdriver.FirefoxProfile()
        profile.set_preference("browser.download.folderList", 2)
        profile.set_preference("browser.download.manager.showWhenStarting", False)
        profile.set_preference("browser.download.dir", 'D:\downloads')
        profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/x-gzip")
        driver = webdriver.Firefox()
        driver.get(urlpage)
从我所看到的,应该只是下载文件到我的D:驱动器在下载文件夹,但当我运行代码,网页打开,然后问我是否要查看或下载文件。代码有什么问题吗?还是我做错了什么


不确定这是否是重要信息,但我正在使用PyCharm作为我的IDE

这是您应该使用的脚本,这将文件保存在系统默认下载文件夹中

FF_options = webdriver.FirefoxProfile()
FF_options.set_preference("browser.helperApps.neverAsk.saveToDisk","application/zip")
driver= webdriver.Firefox(firefox_profile=FF_options)
如果要将下载的文件保存在特定位置,请添加以下Pref

# change the path here, current line will save in the working directory meaning 
# the location where your script is.
FF_options.set_preference("browser.download.dir", os.getcwd()) 
FF_options.set_preference("browser.download.folderList",2)

它们在web浏览器中更改了太多元素,因此最终有些元素不起作用。在这一行中创建驱动程序时,您没有使用prefs
driver=webdriver.Firefox()
@supputuri那么我如何使用它呢?我从来没有真正使用过Python,我假设是在您设置概要文件时让我检查并发布答案。顺便说一句,确保下载内容类型与上面
saveToDisk
行中指定的类型匹配。我刚刚指定了generic
application/zip
。如果您在查找内容类型时需要帮助,请告诉我。请检查并让我知道它是如何运行的。我将在将来检查,我被告知要在chromium中试用它