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
- 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
ASKER
An easy working example with an url included would help. (without the user agent funct. etc. )
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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/drat es/";
$name = "0701.htm";
use Socket;
if ( $ARGV[0] ) { $_=$ARGV[0]; } else { die "Usage: geturl.pl url"; }
($notused,$host,$path,$nam e)= /(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/h tml/source /$name") || die "Error opening file: $name";
print OUT $buff;
close(OUT);
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/drat
$name = "0701.htm";
use Socket;
if ( $ARGV[0] ) { $_=$ARGV[0]; } else { die "Usage: geturl.pl url"; }
($notused,$host,$path,$nam
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/h
print OUT $buff;
close(OUT);
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.