Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

HTML::DOM traverse

by jai_dgl (Beadle)
on Apr 14, 2008 at 10:13 UTC ( [id://680242]=perlquestion: print w/replies, xml ) Need Help??

jai_dgl has asked for the wisdom of the Perl Monks concerning the following question:

I am using HTML::DOM module in perl, my requirement is, I have to traverse the enitre DOM and find <img> tag and remove <img> where ever its found in the HTML. please help me to traverse the DOM and find a specified tag and delete it. Thanks

Replies are listed 'Best First'.
Re: HTML::DOM traverse
by holli (Abbot) on Apr 14, 2008 at 10:18 UTC
Re: HTML::DOM traverse
by ikegami (Patriarch) on Apr 14, 2008 at 10:34 UTC

    If you're intent is to sanitize HTML submitted by your users, I'm don't think HTML::DOM (or any other module that constructs a tree from the HTML before doing anything else) is the right route.

    If not, here's what you asked:

    for my $img ( $dom_tree->getElementsByTagName('img') ) { $img->delete(); }

    Untested. Assumes getElementsByTagName returns HTML::Element objects.

      Thanks its Working great.

Log In?
Username:
Password:

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

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

    No recent polls found