Tal Peretz
Tal Peretz

Reputation: 515

Download XLS files automatically from a website

How can I download XLS files from a website automatically? My client enters user name and password for login into the website and from then i need to download list of XLS files, one by one and saved them into one path. the files link are inside a html table. need your help guys

Upvotes: 0

Views: 927

Answers (2)

Dmitry Nogin
Dmitry Nogin

Reputation: 3750

You can do it in the following way... Browser behaviour differs, but you can initiate downloading of many files per one action. I think this is the best possible solution you might have in a browser.

You can create a temporary set of hidden iframes, initiate download by GET or POST inside of them, wait for downloads to start and remove iframes:

<!DOCTYPE HTML>
<html>
<body>
  <button id="download">Download</button> 

  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
  <script type="text/javascript">

     $('#download').click(function() {
       download('http://nogin.info/cv.doc','http://nogin.info/cv.doc');
     });

     var download = function() {
       for(var i=0; i<arguments.length; i++) {
         var iframe = $('<iframe style="visibility: collapse;"></iframe>');
         $('body').append(iframe);
         var content = iframe[0].contentDocument;
         var form = '<form action="' + arguments[i] + '" method="GET"></form>';
         content.write(form);
         $('form', content).submit();
         setTimeout((function(iframe) {
           return function() { 
             iframe.remove(); 
           }
         })(iframe), 2000);
       }
     }      

  </script>
</body>
</html>

Upvotes: 3

Gregory A Beamer
Gregory A Beamer

Reputation: 17010

One cheap and easy way is to set up the web browser control and use it to log in. You now have credentials for the site. Then, have a button fire off the URIs for each of the XLS files, opening using the same context, and then save to the drive.

You can actually hide the control from the user.

Since you appear to be in control of the site, I would also consider using a different methodology to serve these bits, like a WCF service.

Upvotes: 0

Related Questions