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

I am a newbie so please excuse my mistakes.

I am trying to save the contents of a link and have been unsuccesfull so far. I have tried to use WWW::Mechanize and it works well when the target of the link is a html page but NOT when it is a data page.

eg:
use LWP::Simple;
getstore("http://ichart.finance.yahoo.com/table.csv?s=AMZN&d=8&e=30&f=2004&g=d&a=4&b=16&c=1997&a mp;ignore=.csv","tmp.txt");

Does not store the contents of the link. Similarly this did not save the link:

use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
$tempfile="tmp.txt";
$mech->agent_alias( 'Windows IE 6' );
$url="http://ichart.finance.yahoo.com/table.csv?s=AMZN&d=8&e=30&f=2004&g=d&a=4&b=16&c=1997&i gnore=.csv"; $mech->get( $url,":content_file"=>$tempfile );

When viewed in a browser , If I click the link I am presented with a "save as" window. Does anyone know How I can resolve this problem?

Thanks

Replies are listed 'Best First'.
Re: Saving contents of a Target Link.
by Corion (Patriarch) on Sep 30, 2004 at 15:55 UTC

    I have no problem like you describe:

    C:\temp>perl -MLWP::Simple -e "getstore 'http://ichart.finance.yahoo.c +om/table.csv?s=AMZN&d=8&e=30&f=2004&g=d&a=4&b=16&c=1997&ignore=.csv', +'test.tmp'" C:\temp>dir test.tmp Datenträger in Laufwerk C: hat keine Bezeichnung. Datenträgernummer: 6C76-F753 Verzeichnis von C:\temp 30.09.2004 17:59 88.703 test.tmp 1 Datei(en) 88.703 Bytes 0 Verzeichnis(se), 65.836.314.624 Bytes frei C:\temp>perl -ple "exit if $.>5" test.tmp Date,Open,High,Low,Close,Volume,Adj. Close* 29-Sep-04,39.45,40.92,39.36,40.84,9918800,40.84 28-Sep-04,40.15,40.33,38.97,39.43,11902900,39.43 27-Sep-04,40.91,41.01,39.75,39.93,8397400,39.93 24-Sep-04,41.81,41.91,40.85,40.94,6205700,40.94 C:\temp>

    I also don't have the problem you describe using WWW::Mechanize:

    C:\temp>type mech.pl use WWW::Mechanize; my $mech = WWW::Mechanize->new(); $tempfile="tmp.txt"; $mech->agent_alias( 'Windows IE 6' ); $url="http://ichart.finance.yahoo.com/table.csv?s=AMZN&d=8&e=30&f=2004 +&g=d&a=4&b=16&c=1997&ignore=.csv"; my $res = $mech->get( $url,":content_file"=>$tempfile ); warn $mech->status; C:\temp>perl -w mech.pl 200 at mech.pl line 7. C:\temp>perl -ple "exit if $.>5" tmp.txt Date,Open,High,Low,Close,Volume,Adj. Close* 29-Sep-04,39.45,40.92,39.36,40.84,9918800,40.84 28-Sep-04,40.15,40.33,38.97,39.43,11902900,39.43 27-Sep-04,40.91,41.01,39.75,39.93,8397400,39.93 24-Sep-04,41.81,41.91,40.85,40.94,6205700,40.94

    So the problem must be somewhere else, like maybe you haven't shown us the actual code you are using, or you are not allowed to write into the current directory or some other problem... You should check what the actual result code is you get from WWW::Mechanize, maybe it is also a network problem.

Re: Saving contents of a Target Link.
by MiniMe (Initiate) on Sep 30, 2004 at 16:15 UTC
    Tks Corion, The problem was an embedded carriage return in the url. I am mortified that I did not see that earler. Tks again