jimmyredboy has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone have any experience pulling MS Excel files off of the web? I have been unable to get a valid Excel file from a website. Here is what happens (Windows 2000 box, ActiveState perl):
  1. Connect to server, then authenticate
  2. Use LWP to GET the file of interest.
  3. Save the file to disk
When I do this, the file cannot be read by Excel, nor will ParseExcel read the file. I compared the downloaded file to a "reference" file that I created by opening the Excel file in IE & saving to disk. The files are very, very similar, but different. Is there some special MS foo that is tripping me up, or am I missing something obvious like character encodings? Here is an abbrviated version of my code:
use strict; use warnings; use LWP; use Spreadsheet::ParseExcel; my $url = 'http:// blah blah /login.asp'; my $browser = LWP::UserAgent->new; $browser->cookie_jar({}); my $response = $browser->post( $url, [ 'password' => 'pass', 'userid' => 'user', 'btnsubmit' => 'Submit', ] ); $url = "http://blah blah getdata_RS.asp"; $response = $browser->get( $url ); my $exceldata = $response->content; open (FILE, "> c:\\test.xls");
The file that I am pulling down is only one sheet, not an entire workbook. Thanks!

Replies are listed 'Best First'.
Re: Download Excel File off web
by bart (Canon) on Jan 30, 2004 at 17:31 UTC
    It seems you forgot binmode on your output file handle.

    But actually, I'd try to use LWP::Simple's getstore() function, and let it save the file as binary for you.

Re: Download Excel File off web
by pzbagel (Chaplain) on Jan 30, 2004 at 17:35 UTC

    On Windows you have to run binmode on the filehandle after opening it in order to write binary data to it correctly. You generally do not need to do this on *nix.

    Later

Re: Download Excel File off web
by jimmyredboy (Initiate) on Jan 30, 2004 at 18:49 UTC
    Bingo -- that did the trick. Thanks.