1

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!

1

2 Answers 2

1

You can change download folder by using specific preferences when starting your driver. You should set this:

("download.default_directory", yourWantedPath)

Not sure how are you starting and configuring your driver so can't help you with more code, but this is the preference you are looking for.

You could find useful things here.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.