user1572656 user1572656 -4 years ago 61
HTML Question

How do I delete a specific HTML <table> with Perl?

I need to delete certain tables based on the contents of the table. I parsed the HTML using

to build an HTML tree.

I used
replace_with_content
to delete the table but that only removes the table tag and leaves the contents of the table.

Please note that the tables are nested.

my $content = get($url);

my $tree = HTML::Tree->new();
$tree->parse($content);

my (@table_tags) = $tree->look_down( '_tag' , 'table' );
my $string = $table_tags[0]->as_HTML;

my $tree2 = HTML::Tree->new();
$tree2->parse($string);

my (@table_tags2) = $tree2->look_down( '_tag' , 'table' );
$table_tags2[3]->replace_with_content();

Answer Source

What about using delete instead of replace_with_content?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download