?
Solved

post-process information from other web-server

Posted on 1998-01-10
4
Medium Priority
?
155 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 1000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
It is becoming increasingly popular to have a front-page slider on a web site. Nearly every TV website,  magazine or online news has one on their site, and even some e-commerce sites have one. Today you can use sliders with Joomla, WordPress or …
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…
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 …
Suggested Courses

752 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