in reply to Merging two anchors with HTML::TreeBuilder

forget about "splice", detach/delete/remove the tag you dont want, and push_content to the tag you want, or replace it with a new tag (replace_with )

  • Comment on Re: Merging two anchors with HTML::TreeBuilder

Replies are listed 'Best First'.
Re^2: Merging two anchors with HTML::TreeBuilder
by Anonymous Monk on May 10, 2016 at 06:26 UTC
    HTML::TreeBuilder::XPath with htmltreexpather.pl makes it easier to find what you want, like the second link in each tablecell
    use HTML::TreeBuilder::XPath; #~ my $root = HTML::TreeBuilder->new; my $root = HTML::TreeBuilder::XPath->new; for my $secondlink ( $root->findnodes( '//td/a[2]' ) ){ my $td = $secondlink->parent; my $newtext = $td->as_trimmed_text ; $secondlink->delete_content; $secondlink->push_content( $newtext ) ; $secondlink->detach; $td->delete_content; $td->push_content( $secondlink ); }

      Thanks, both. I've gone with the HTML::TreeBuilder::XPath option.