https://metacpan.org/module/HTML::Tree#DESCRIPTION
https://metacpan.org/module/HTML::Tree#DESCRIPTION
https://metacpan.org/module/HTML::Tree#new_from_content
#!/usr/bin/perl --
use strict; use warnings;
use HTML::Tree;
use Data::Dump qw/dd pp /;
my $t = HTML::Tree->new_from_content(q{
<a href="1">1</a>
<a href="q">q</a>
<a src="ERR">ERR</a>
<img src="2">
<link href="3">
<link src="4ERR">
});
dd( $t );
for my $l ( $t->look_down( qw/ _tag a /) ){
{
local $$l{_parent};
dd( $l );
}
dd( ref $l, $l->tag, $l->attr('href'), $l->as_text );
}
for my $leat (@{ $t->extract_links( ) }) {
my($link, $element, $attr, $tag) = @$leat;
print
"Hey, there's a '$tag' that links to ",
$link, ", in its '$attr' attribute, at ",
$element->address(), ".\n";
}
print "\n", $t->as_HTML(undef, ' ');
__END__
see more stuff Re: TreeBuilder and encoding,
Use the twig :) Processing XML efficiently with Perl and XML::Twig
See also htmltreexpather.pl and xpather.pl
htmltreexpather.pl , Parsing HTML / Re^4: Parsing HTML, A regex question , NASA's Astronomy Picture of the Day / Re: NASA's Astronomy Picture of the Day , Re: Extracting HTML content between the h tags, Re^2: Help With Online Table Scraper, Re^4: web::scraper using an xpath, .... HTML Parser suggestions
xpather.pl
Re: Get Node Value from irregular XML (xpather.pl)
Re: Having trouble with siblings
Re^2: XML parsing and Lists
Re: Counting number of child nodes based on element value (typos)
Re^3: Extracting specific childnodes (xpath whitespace)
Re^3: Extracting specific childnodes (play xmllint --shell )
Re: How do i get value of an element if the next elememnt has specific value in XML::LibXML using Xpath?
Re: How do i get value of an element if the next elememnt has specific value in XML::LibXML using Xpath?
Re: How to parse xml with namespase vale in XMl:LibXML? ( XPath error : Undefined namespace prefix )
Re^2: How to parse xml with namespase vale in XMl:LibXML? (xmllint --shell setns / xpathtester)
There is a better way :) because xml::parser is low level, you should parse html/xml with xpath/twig/dom, Re: How to grab a portion of file with regex (don't),
HTML Parser suggestions
See also the real discouragement Oh Yes You Can Use Regexes to Parse HTML! and the real encouragement Re^2: parsing XML fragments (xml log files) with... a regex
How do I match XML, HTML, or other nasty, ugly things with a regex?
How do I remove HTML from a string?
Re: Parsing webpages
See htmltreexpather.pl , Parsing HTML / Re^4: Parsing HTML, A regex question , NASA's Astronomy Picture of the Day / Re: NASA's Astronomy Picture of the Day , Re: Extracting HTML content between the h tags, Re^2: Help With Online Table Scraper, Re^4: web::scraper using an xpath, .... HTML Parser suggestions
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.