PDA

View Full Version : wget problem


hkucsis
04-15-2003, 07:07 AM
Hi,

I am writing a cgi script that uses wget to get a page and then us open() to read the page content.

Here is my situation:
Suppose I wget a page and save it as a.html and then use open(). The problem is I can't read the content of a.html. I can read the file in another script. I guess this is due to when I try to read a.html, wget has not yet finished.....

How to solve this problem ?

Thanks.

here is my code: (for demontrative purpose only)

system("wget -O search_temp/abc http://www.google.com/") ;
open(fd, "search_temp/abc") ; // can't read anything
@file_content = <fd> ;
close (fd) ;

YUPAPA
04-15-2003, 10:50 PM
HiHi~

Maybe you don't have wget installed or you can't use the system command?

Try this instead


#!/usr/bin/perl
use LWP::UserAgent;

my $ua = new LWP::UserAgent;
my $url = 'http://www.yupapa.com';
my $request = new HTTP::Request('GET', $url);
my $response = $ua->request($request);

if($response->is_success) {
print $response->as_string();
} else {
print "Fail\n";
}

__END__



This can be done without having actually to save the file to your machine.

YUPAPA
04-15-2003, 10:53 PM
Originally posted by hkucsis

system("wget -O search_temp/abc http://www.google.com/") ;
open(fd, "search_temp/abc") ; // can't read anything
@file_content = <fd> ;
close (fd) ;


I tried it and it works ok bor... :)