This little snippet should get you most of the way:
use HTML::TreeBuilder::XPath; my $html = q|<div class="listing"> Agave parryi&nbsp;&nbsp;&nbsp;&nbsp; ... </div>|; $html =~ s/&nbsp;/ /g; my $tree = HTML::TreeBuilder::XPath->new_from_content($html); my @nodes = $tree->findnodes('//div[@class="listing"]'); for my $node (@nodes) { my @contents = $node->content_list; for my $content (@contents) { if (ref $content) { my $text = $content->as_text or next; my $tag = $content->tag; print "<$tag> $text\n\n"; } else { print "$content\n\n"; } } }
Output:
Agave parryi <span> Parry's agave $20.00 3 quart $12.00 Quart <span> Native Sun to part shade Zones 5-10 Family: <i> Amaryllidaceae From the Southwest comes this lovely agave. Thick spiny leaves adorn t +his hardy agave. Ultimate clump size is about 36" with each leaf bein +g maybe 5" across. The flower stalk can reach 12 feet tall. Please pl +ant in well drained soil in a place where children don't play. <span> Hummingbirds

In reply to Re: HTML Parsing (ick) by tangent
in thread HTML Parsing (ick) by dbarron

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.