0

I'd like to download multiple files from a single website, but the biggest quirk I have is that the server automatically generates a random filename upon requesting the file to download. The issue here is then I won't know which file is which, without having to manually go through each file. However, on the site that has the links to download the files, they all have a name. For example...

File name     ->  Resultant file name(fake file names)
Week1.pdf         2asd123e.pdf
Week1_1.jpg       dsfgp142.jpg
.           
.
Week10.pdf        19fgmo2o.pdf
Week11.pdf        0we5984w.pdf

If I were to download them manually by myself, I would type click "download" and a popup "Save as" menu comes up, which gives me the option to change the file name manually, then click ok to confirm the download, to which it starts downloading.

Currently, my code is made to open up the website, log into my account, go to the files page, and then find a file, with it's corresponding server request link. IE: . I am able to store the name of the file, "Week1.pdf" into a variable, and click on the request link, but the only problem is that the Save as menu, doesn't have the ability to change the name of the filename, and only gives me the option to view the file, or Save the file immediately. I've looked around a little, and tried to play around with the Firefox profile settings, but nothing has worked. How would I go about solving this problem?

Thanks

Matt I
  • 165
  • 3
  • 11

1 Answers1

0

I can think of a few things that you might try...

  1. After the file is saved, look in the downloads folder for the most recently saved file (with the correct extension) using time stamps. This will probably be OK as long as you aren't running this threaded.

  2. Get the list of files in the download directory, download the file, find the file that doesn't exist in the list of files. Again this should be safe unless you are running this threaded.

  3. Create a new folder, set the download directory to the newly created folder, download the file. It should be the only file in that directory. As far as I know, you can only set the download directory before creating the driver instance.

In each of these cases, if you plan to download multiple files I would rename each file as you download them or move them into some known directory to make it easier on yourself.

There's another method I ran across in another answer.

JeffC
  • 22,180
  • 5
  • 32
  • 55
  • 1
    I was thinking of doing that initially, and it seems like that's the most plausible way of doing it. Download the file first, with the random name, such as 234qwrmsdf.pdf, and then once the download is complete, just change the file name back to Week1.pdf. My only gripe is that it would take ages to do so, so hopefully theres a way to do it threaded. Thanks! – Matt I Jan 01 '18 at 03:57