Skip to content
Advertisement

How to change saved PDF page name with Selenium + Chromedrive

I have a script that uses Selenium Python to download a PDF page made based on this question

My goal at the moment is to change the name of this file so that it is located with the name I chose and then change the destination folder of the saved file.

My doubts are: Where should I change so that the file is saved with the name I choose?

Even with the changes made to the “prefs=” variable, the file continues to be saved in the default chrome directory.

At the moment I have the following code:

JavaScript

Advertisement

Answer

Change download.default_directory to savefile.default_directory so your saving location works.

Sadly I think we can’t change the filename before download, but you can rename your file after download, by renaming the latest file in download folder:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement