I was getting some odd output from HTML::TableExtract. Closer inspection of the html revealed 29 open table tags and 10 closing table tags. H::TE is allowed to be confused by a mess like that.

I tried with HTML::TreeBuilder, only looking for the cells we are interested in.

(I saved the source to a file for testing)

#!/usr/bin/perl use strict; use warnings; use HTML::TreeBuilder; my $filename = q{html/monk.html}; my $r = HTML::TreeBuilder->new; $r->parse_file($filename); # <td width="48%" valign="top"> my @cells = $r->look_down( _tag => q{td}, width => q{48%}, valign => q{top}, ); my $i; for my $cell (@cells){ my $bold = $cell->look_down(_tag => q{b}); print $bold->as_text, qq{\n}; for my $item ($cell->content_refs_list) { next if ref $$item; print $$item, qq{\n}; } my $link = $cell->look_down( _tag => q{a}, ); print $link->attr(q{href}), qq{\n\n}; last if $i++ > 2; }
output (extract)
SERVPRO® of Central Alabama Wilson, David & Christie Phone: (205)678-2224 Fax: (205)678-2226 http://www.servpro.com/franchises/enhanced_asp/default.asp?fn=2196 SERVPRO® of South Alabama Johnson, Walter G. Phone: (251)661-9282 Fax: (251)660-7539 http://www.servpro.com/franchises/enhanced_asp/default.asp?fn=2212 SERVPRO® of Northern Alabama Wilson, David & Christie Phone: (205)678-2224 Fax: (205)678-2226 http://www.servpro.com/franchises/enhanced_asp/default.asp?fn=2233 SERVPRO® of Central Alabama II Wilson, David & Christie Phone: (205)678-2224 Fax: (205)678-2226 http://www.servpro.com/franchises/enhanced_asp/default.asp?fn=2226
Update: Tidied up the output

In reply to Re: PERL HTML::TableExtractor by wfsp
in thread PERL HTML::TableExtractor by jdlev

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.