Python 和 Selenium : Force no download window

标签 python selenium firefox automated-tests geckodriver

使用geckodriver和 Firefox v63,我尝试从网站下载 CSV 文件,但不会出现下载提示。

我的代码是:

from selenium import webdriver

profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2)  # custom location   
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', '/Path/to/download')
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'text/csv')

browser = webdriver.Firefox(profile, options=options)
browser.get('http://www.website.com')

download = browser.find_element_by_css_selector('selector')
download.click()

它不起作用,我不明白为什么。我没有收到错误并且代码执行,但它显示 Firefox 下载窗口,并且仅在单击“确定”时才保护文件。我想避免手动点击,因为我想自动执行该任务。

最佳答案

打开 FireFox 并尝试一下

Goto Preferences -> General

然后选择您要下载到的文件夹并取消选中“始终询问”

尝试一下,祝你好运!

关于Python 和 Selenium : Force no download window,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53474953/

相关文章:

firefox - Selenium:如何确保 back() 导航在不同站点上按预期工作?

asp.net - 如何强制浏览器转到服务器端而不是从浏览器缓存获取数据

Python、Pyautogui 和 CTRL-C

Python 对于 1 的左移和 2 的幂的行为不同

java - 我如何接受特定网站上的 cookie?

firefox - 在 Selenium IDE 中关闭新打开的选项卡或窗口

firefox - 为什么 FF 51.0.1 会屏蔽页面证书?

Python:使用多个文本文件时如何仅使用 1 列?

python - 在 SQLAlchemy 中使用 MariaDB 的 COLUMN_GET()

selenium - Behat with Selenium Hub和Firefox错误:无法打开连接:从webdriver接收到的有效载荷有效,但意外出现json