1

I'm using Python & Selenium to download a large number of files (yes, I do need to). Currently, to make sure a file downloads, I have a simple time.sleep() statement, but I'd like to both improve efficiency and make guarantees that I've downloaded each file.

Unfortunately, I don't have a list of file paths such that I can use some other suggested solutions for general file downloads.

What I'm dealing with is the following on-click javascript:

onclick="javascript:__doPostBack('ctl00$MainContent$GridView1','OpenFile$0')

So I'd like to be able to detect that one file has begun downloading before clicking on the next one.

Any suggestions?

pshee
  • 83
  • 8
  • 1
    you should probably implement in the other way round by checking the file has downloaded completely (by using **os.path.exists()** before clicking the next. – Anzel Jan 06 '15 at 19:50

1 Answers1

0

Similar approach to what @Anzel suggested.

Use watchdog to watch the Browser Downloads directory. Once there is a new file appearing, you know that a download has started. See also:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Would this work if I'm downloading multiple files at the same time? My current code has multiple browsers open at the same time, downloading files to the same directory. – pshee Jan 06 '15 at 21:17
  • @pshee depends. If you know the filename that should appear - than yes. Or, if you can create a separate sub-directory in the main Downloads directory and watch them separately - then also yes. – alecxe Jan 06 '15 at 21:19