Solved

post-process information from other web-server

Posted on 1998-01-10
4
139 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to dynamically set the form action using jQuery.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now