1

Using geckodriver and Firefox v63, I try to download a CSV file from a website without causing the download prompt to appear.

My code is:

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()

It does not work and I don't understand why. I don't get an error and the code executes, but it shows the Firefox download window and only safes the file if I click OK. I'd like to avoid clicking manually because I want to automate the task.

Meeep
  • 77
  • 1
  • 6
  • debanjanB is correct, thank you for the link. it was the mime type. Using this setting: profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'text/plain,application/vnd.ms-excel,text/x-csv,application/csv,application/x-csv,text/csv,text/comma-separated-values,text/x-comma-separated-values,text/tab-separated-values') it works. Thanks. – Meeep Nov 26 '18 at 11:20

1 Answers1

0

Open up FireFox and try this

Goto Preferences -> General

and then pick the folder you want to download to and uncheck the "always ask"

Give this a shot, good luck!

exe
  • 354
  • 3
  • 23
  • Thanks Kobe. "Always ask..." is unchecked. "Safe file to" is checked and the folder is the same as defined in the python file. – Meeep Nov 26 '18 at 05:06