Solved

post-process information from other web-server

Posted on 1998-01-10
4
143 Views
Last Modified: 2013-12-25
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
0
Comment
Question by:nadia
  • 2
4 Comments
 
LVL 5

Expert Comment

by:icd
ID: 1831817
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.

0
 

Author Comment

by:nadia
ID: 1831818
An easy working example with an url included would help. (without the user agent funct. etc. )
0
 
LVL 2

Accepted Solution

by:
paul_t earned 250 total points
ID: 1831819

======= geturl.pl

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,">$name") || die "Error opening file: $name";

print OUT $buff;

close(OUT);


0
 

Author Comment

by:nadia
ID: 1831820
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);

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question