Solved

post-process information from other web-server

Posted on 1998-01-10
4
150 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Powershell  and PSExec = Password failure 5 26
Logon script fails 23 69
AWK: Am I duplicating the comma delimiter in this code? 5 38
-OutVariable to Global 1 31
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…
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

738 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