0

I am trying to download a .csv file from a website X using Selenium Firefox, but it keeps saving it in the Download folder instead of the path I set. I would fancy some help here.

The FirefoxProfile has a "DeprecationWarning", therefore I am strictly using the Options() configuration. I tried using "\", "/" and "\\".

from selenium import webdriver
from selenium.webdriver.firefox.options import Options


download_path = "C:\a\very\nice\path"
options = Options()
options.set_preference("browser.download.folderList", '2')
options.set_preference("browser.download.manager.showWhenStarting", False)
options.set_preference("browser.download.dir", download_path)
options.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/csv")

browser = webdriver.Firefox(executable_path=path_gecko,
                            options=options) 

1 Answers1

0

I solved the problem, still no idea where the problem was, I changed

download_path = r'C:\Users\rest\of\the\path'
  • Your problem was the path. The difference between the question and solution is the r before the path which tells python to take the string literally. Python, "C:\n\t" or 'C:\n\t' are a C: followed by a new line followed by a tab. on the other hand, r"C:\n\t" or r'C:\n\t' is actually the string "C:\n\t" – user304584 Jan 10 '23 at 11:45