Python Forum

Full Version: Changing Download Path for ChromeOptions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am attempting to write a Python script which logs into a site using Selenium, and thendownloads the images from a set of links passed into the script, the sources of which are located on the site I just logged into. The script is functional, but the one thing I can't get to work is that I seem to be unable to change the download path for where I want to save the files I download. I have tried using the following code to change the directory and it still tries to download the files into C:/Users/user/Downloads:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains

import pyautogui as gui
import urllib.request as url
import requests
import time

import re
import os
from pathlib import Path
import shutil

preferences = {
"download.default_directory": r"D:\xxx_content\pregs\preg_downloads\40k_dataset",
"download.prompt_for_download": False,
"download.directory_upgrade": True
}

options = webdriver.ChromeOptions()         
options.add_argument('--disable-download-notification')
options.add_argument('--start-maximized')
options.add_experimental_option("prefs", preferences)

driver = webdriver.Chrome(options=options, executable_path=r"C:/bin/chromedriver.exe")  
I have searched this for a while, and all the solutions I have tried fail to achieve what they say they're meant to. I am using Chrome 85 and the corresponding ChromeDriver.