Alastard Alastard - 4 years ago 298
Python Question

How to change chrome's default download path with selenium?

My scenario is: I had to write a script to download a huge amount of files by using Selenium and Python 3.6, and now, I have to download files using the same technologies.

The point is that this script won't be executed on my own computer.

Is it possible, using chrome webdriver, to get the default download folder of chrome?

As of now I have this code:

dlPth="C:\\Users\\genieelecpsim\\Downloads\\"
nwPth="C:\\Users\\genieelecpsim\\Downloads\\Exports"
for file in os.listdir(dlPth):
if file.startswith("export") and file.endswith(".csv"):
print(str(years[i])+"-"+str(months[j])+"-"+str(days[k]))
newfile=os.path.join(nwPth,str(years[i]) +"-" +(str(months[j]) if months[j]>=10 else "0"+str(months[j]))+"-" +(str(days[k]) if days[k]>=10 else "0"+str(days[k])) +".csv")
shutil.move(os.path.join(dlPth,file),newfile)
print (newfile)
break


What I want to do here is something like:

dlPth=# Chrome's default download directory
nwPth=dlPth+"\\Export"


Is it possible? Thanks for your response!

EDIT: First of all, thanks to all for your quick answers, and it seems that my topic's a dupplicate, but as I'm not using the same configuration than this one, I'm wondering if this method works with py3.6 and Selenium 3.0.2... I'm sorry I can't directly comment your answers as I'm new here, but thanks to everyone!

Answer Source

The answers did not really help me, but thanks anyway. I find another way to do so by using the OS library:

# dlPth will be the path to the download directory of the current user (on the system)
dlPth=os.path.join(os.getenv('USERPROFILE'), 'Downloads')

# destPth will just be a directory where I'll put all my (renamed) files in.
destPth=dlPth+"\\Exports\\"

Thanks for answering, I posted the answer here so anyone looking for some help on this topic will be able to see it

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download