Link to home
Start Free TrialLog in
Avatar of nadia
nadia

asked on

post-process information from other web-server

I am looking for a snipped of code (in perl) for the following function:

- get information (whole page) i.e. http://www.imf.org/external/np/tre/sdr/drates/0701.htm and than it should save it as 0701.htm to the local drive.

Thanks
Avatar of icd
icd

There is a very good article which describes in great detail how to do all of this (with the exception of writing the file to the local drive, which is trivial) at:

http://w3.stonehenge.com/merlyn/WebTechniques/col11.html

The script also does more, in that it processes the date in the file, but you can easily omit such processing.

Avatar of nadia

ASKER

An easy working example with an url included would help. (without the user agent funct. etc. )
ASKER CERTIFIED SOLUTION
Avatar of paul_t
paul_t

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nadia

ASKER

Thank Paul!

What is ment with "ARGV"?
I get a Server Error with that:

#!/usr/bin/perl

# geturl.pl
###########

$host = "imf.org";
$path = "/external/np/tre/sdr/drates/";
$name = "0701.htm";

use Socket;

if ( $ARGV[0] ) { $_=$ARGV[0]; } else { die "Usage: geturl.pl url"; }

($notused,$host,$path,$name)= /(http:\/\/)([^\/]*)(.*\/)([^\/]*\w$)/;

print "Host: $host\nDocument: $path"."$name\nFile: $name\n";

$hostAddr = inet_aton($host) || die "Cannot lookup host $host";
socket( S, PF_INET, SOCK_STREAM, getprotobyname('tcp') ) || die "socket: $!";
connect( S, sockaddr_in(80,$hostAddr) ) || die "Unable to connect to $host port 80: $!";

$req="GET $path/$name\n";

syswrite( S, $req, length($req) );

$read=sysread( S, $buff, 1000);

while ($read > 0) { $read = sysread( S,$buff,10,length($buff)); }

open(OUT,">/web02/domain/html/source/$name") || die "Error opening file: $name";

print OUT $buff;

close(OUT);