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:

for file in os.listdir(dlPth):
if file.startswith("export") and file.endswith(".csv"):
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")
print (newfile)

What I want to do here is something like:

dlPth=# Chrome's default download directory

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.

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