Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^4: Ignoring specific html tags before parsing

by Anonymous Monk
on Oct 08, 2013 at 01:36 UTC ( [id://1057337]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Ignoring specific html tags before parsing
in thread Ignoring specific html tags before parsing

>>What is your actual goal? I want to ignore tables and img tags from html when parsing and getting embedded text from the html files.
  • Comment on Re^4: Ignoring specific html tags before parsing

Replies are listed 'Best First'.
Re^5: Ignoring specific html tags before parsing
by Anonymous Monk on Oct 08, 2013 at 02:21 UTC
    #!/usr/bin/perl -- use strict; use warnings; use XML::LibXML 1.70; ## for load_html/load_xml/location Main( @ARGV ); exit( 0 ); sub Main { my $loc = shift or die " Usage: $0 ko00010.html $0 http://example.com/ko00010.html\n\n"; my $dom = XML::LibXML->new( qw/ recover 2 / )->load_html( location => $loc, ); for my $node ( $dom->findnodes( '//table | //img | // script | // +style | //noscript ' ) ){ $node->detach; } print $dom->find('//body')->[0]->textContent,"\n"; } sub XML::LibXML::Node::detach { my( $self ) = @_; $self->paren +tNode->removeChild( $self ); }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 03:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found