Forgot your password?
typodupeerror
Programming

Journal: Changing HTML::Element node attributes

Journal by xhunter

I'm working with HTML::Element via HTML::TreeBuilder and its attractive look_down method. I am curious about changing the attributes of a tag for an HTML tree object.

Let's say I start at the root element 'hmtl', and I want to add a summary to the second table.

use LWP::Simple;

my $url = 'http://fire.org/';

my $content = get($url);

use HTML::TreeBuilder;

my $page_tree = HTML::TreeBuilder->new_from_content($content);

my @tables = $page_tree->look_down(_tag=>'table');

my $summary = 'make it for real';

The syntax for setting an attribute is:

$tables[1]->attr('sumary', 'Put your summary here');

The following syntax does NOT work

$tables[1]->attr('summary') = $summary;

Ernest asks Frank how long he has been working for the company. "Ever since they threatened to fire me."

Working...