Is there a way to remove an entire row (html tags ‘n all) from an HTML Table with HTML::TableExtract?
Mucking around with the sample code from CPAN, this is what I’ve tried so far:
use HTML::TableExtract qw(tree);
my $te = HTML::TableExtract->new( headers => [qw(name type members)] );
# get $html_string out of a file...
$te->parse($html_string);
my $table = $te->first_table_found();
my $table_tree = $table->tree;
$table_tree->row(4)->replace_content('');
my $document_tree = $te->tree;
my $document_html = $document_tree->as_HTML;
# write $document_html to a file ...
Now, as the name suggests, ‘replace_content()’ in the line $table_tree->row(4)->replace_content(''); removes the content of row 4, but the row itself remains in markup. I need to get the tags and everything in-between removed as well.
Any ideas?
What you want is the
parentanddeletemethodsSee the docs for HTML::Element and for HTML::Element::delete
UPDATE
Ok, click that checkmark and mark this one as answered….Here it is:
Also, NOTE, you need the () parens around $p! If you don’t have parens don’t get back a reference.
For me, with the above Perl code working on this HTML,
I get this as a result of printing
$document_htmlNotice that there is no empty
<tr></tr>