Hi everyone!

I'm having a problem with HTML::TableExtractor module. I've been fighting it all night long. If you guys could help, I'd be very grateful!

Let's say I have a table in HTML, please take a look at it's code:

<html> <head> <title> Some animals and letters: </title> </head> <body> <table border = "1"> <caption> <h4>table</h4> </caption> <thead> <tr> <th></th> <th colspan="3">1st header</th> <th colspan="3">2nd header</th> <th colspan="3">3rd header</th> </tr> <tr> <th></th> <th colspan="3">subhead1</th> <th colspan="3">subhead2</th> <th colspan="3">subhead3</th> </tr> </thead> <tbody> <tr> <td></td> <td>text</td> <td>more text</td> <td>some more text</td> <td>dog</td> <td>bear</td> <td>cat</td> <td>toocan</td> <td>inu</td> <td>pes</td> </tr> </tbody> </table> </body> <html>

and I want to extract or pass somewhere, or change somehow "subhead1" and "subhead2" columns (with the third row!). Here is the perl code for it:

#!/usr/bin/perl use HTML::TableExtract; use Text::Table; use Data::Dumper; use strict; my $content = 'table.html'; my $headers = ['subhead1', 'subhead2']; my $tbl_extr = HTML::TableExtract->new(headers => $headers); my $tbl_out = Text::Table->new(@$headers); $tbl_extr->parse_file($content); my ($table) = $tbl_extr->tables; my $row; foreach $row ($table->rows) { $tbl_out->load($row); } print $tbl_out;

But what I get is:

~/www$ ./tblext.pl subhead1 subhead2 text dog

And I need to get all of the entries at the third row! Could anyone please point to a mistake in the code?

Thank you in advance.

In reply to HTML::TableExtractor and embedded columns by Kyshtynbai

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.