develooper Front page | perl.libwww | Postings from December 2000

Re: Parse and save to file

Thread Previous
From:
tallwine
Date:
December 17, 2000 11:04
Subject:
Re: Parse and save to file
Message ID:
20001217110342.A32549@oreilly.com
On Sun, Dec 17, 2000 at 09:54:12PM +0300, Ivan C Myrvold wrote:
> I want to parse a web page, and have this command in my program:
> 
> $res = $ua->request(HTTP::Request->new(GET => $url), sub {$p->parse($_[0])});
> 
> But I also want this web page on file, so the next line is:
> 
> $res = $ua->request(HTTP::Request->new(GET => $url), 'tvschedule.html');
> 
> Can I combine these two into one, so I do not need to GET the web page two times?
> 
> Ivan

Here's one way.

$res = $ua->request(HTTP::Request->new(GET => $url));
if($res->is_success) {
    saveFunc($res);
    parseFunc($res);
} else {
    print 'Whatever..',"\n";
}

sub saveFunc {
    my $res = shift;
    open(FH,">pageName.html");
    print FH $res->content;
    close FH;
}

sub parseFunc {
    my $res = shift;
    #parse it.
}

-Tim

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About