Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: How do we remove specific HTML tag

by choroba (Cardinal)
on Nov 07, 2021 at 21:40 UTC ( [id://11138558]=note: print w/replies, xml ) Need Help??


in reply to How do we remove specific HTML element

XML::LibXML can open HTML.
#!/usr/bin/perl use warnings; use strict; use XML::LibXML; my $html = 'XML::LibXML'->load_html(location => 'file.html', recover => 1); my $nav2 = $html->find('(//nav)[2]')->[0]; $nav2->parentNode->removeChild($nav2); print $html->toString; # c="d" is gone.

Or, more succinctly in XML::XSH2:

open :r :F html file.html ; rm (//nav)[2] ; ls / ;

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11138558]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-24 04:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found