Skip to content Skip to sidebar Skip to footer

TreeBuilder Get Embedded Nodes

Basically, I need to get the names and emails from all of these people in the HTML code.
use strict;
use warnings 'all';

use LWP::Simple 'get';
use HTML::TreeBuilder;

use constant URL => 'http://pastebin.com/raw/qLwu80ZW';

my $tree = HTML::TreeBuilder->new_from_content(get URL);

my ($table) = $tree->look_down(_tag => 'table', class => 'rgMasterTable');

for my $tr ( $table->look_down(_tag => 'tr') ) {

    next unless my @td = $tr->look_down(_tag => 'td');

    my ($name, $email) = map { $_->as_trimmed_text } @td[0,1];

    printf  "%-17s %s\n", $name, $email;
}

output

Michael Bowen     mbowen@cpcisd.net
Christian Calixto calixtoc@cpcisd.net
Rachel Claxton    claxtonr@cpcisd.net

Post a Comment for "TreeBuilder Get Embedded Nodes"