Hal Wigoda wrote:
>
> I need a perl script to get tags and corresponding links (in pairs)
> from a web page.
>
> Anyone steer me in the right way?

Hi Hal

This should give you some clues, although a lot depends on exactly what you
want. Obviously the variables can be used to do something more useful than to
recreate what the original HTML element might have looked like!

Rob


use strict;
use warnings;

use LWP::Simple;
use HTML::TreeBuilder;

my $html = get 'http://www.cpan.org/';

my $tree = HTML::TreeBuilder->new_from_content($html);
my $links = $tree->extract_links;

foreach (@$links) {
  my ($link, $elem, $attr, $tag) = @$_;
  print qq(<$tag $attr="$link">\n);
}

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to