Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: HTML::LinkExtractor

by simon.proctor (Vicar)
on Aug 20, 2002 at 14:35 UTC ( #191468=note: print w/replies, xml ) Need Help??

in reply to HTML::LinkExtractor

I recently had to do something incredibly similar to this but I made use of HTML::TreeBuilder. My code ran down into something alot shorter (I've re-written mine here so its more of a psuedo code than anything):
while(my ($tag, $att_list) = each %TAGS) { my @list = $tree->look_down('_tag',$tag); foreach my $item (@list) { foreach my $attr(@{$att_list}) { next unless $item->attr($attr); next unless length (my $a = $item->attr($attr)); next if $a =~ /mailto:/; my $target = URI->new_abs($a, $base); next unless $self->compareHosts($target,$url); next unless $self->validScheme($url,['http']); next unless $self->allowed($url); unless(exists $self->[GOOD_LINKS]->{$a}) { $item->attr($attr,$target->rel($base)); push @{$queue}, $target; } } } }

I pasted this, out of interest really, as we've used two different approaches to do roughly the same thing. I was hoping some sort of comparison on technique could be made (etc). However, be aware that mine turns all absolute URLS to relative (or attempts to) as I'm mucking about with the resource later on in my app.




Naturally, $self and $tree refer to objects and methods that I haven't mentioned in my snippet. $tree is the TreeBuilder instance for those who couldn't guess.

Replies are listed 'Best First'.
Re^2: HTML::LinkExtractor
by Aristotle (Chancellor) on Aug 20, 2002 at 15:48 UTC
    HTML::TreeBuilder can consume a lot of memory as it first builds a representation of the document using oodles of objects. It also burdens the CPU more. HTML::TokeParser on the other hand parses the HTML input stream as it comes along, reducing the overhead quite a bit. HTML::TreeBuilder is easy for a quick oneshot script, or nice when you intend to do heavyduty transformation or mangling on the input document's structure, but not a good choice to build an all purpose tool on top of.

    Makeshifts last the longest.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://191468]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2018-05-28 01:47 GMT
Find Nodes?
    Voting Booth?