For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > July 2006 > need script to get tags and links pairs from web pages









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author need script to get tags and links pairs from web pages
Hal Wigoda

2006-07-25, 9:57 pm

I need a perl script to get tags and corresponding links (in pairs)
from a web page.

Anyone steer me in the right way?

hal
chicago
Dr.Ruud

2006-07-26, 3:57 am

Hal Wigoda schreef:

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


CPAN

--
Affijn, Ruud

"Gewoon is een tijger."


Rob Dixon

2006-07-26, 3:57 am

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);
}
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com