Re: TreeBuilder and LWP object
Sean M. Burke (sburke@spinn.net)
Sun, 18 Mar 2001 11:24:13 -0700
At 05:23 PM 2001-03-18 +0100, I....AM.....I wrote:
>hi all,
>I'm trying to parse some html document from LWP object
>like so;
>
>$ua = LWP::UserAgent->new();
>$req = HTTP::Request->new( GET
> => 'http://some.www.url.com' );
>$res = $ua->request($req);
>
>if ( $res->is_success ) {
> kor($res);
>}
[where kor calls TreeBuilder]
Just on principle, I'd suggest checking the content-type too, since feeding
things other than HTML to HTML::TreeBuilder is not nice at all.
if(! $res->is_success ) {
die "well, that didn't work:", $res->status_line;
} elsif($res->content_type() eq 'text/html') {
kor($res);
} elsif($res->content_type() eq 'application/xml') {
...maybe deal with XML/XHTML here?...
} else {
die "Unexpected content-type: ", $res->content_type();
}
--
Sean M. Burke sburke@cpan.org http://www.spinn.net/~sburke/