Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: HTML::LinkExtractor

by simon.proctor (Vicar)
on Aug 20, 2002 at 14:35 UTC ( [id://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.

Cheers

Simon

Update:

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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://191468]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-16 06:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found