text from 1x1 subtable
Kevin Ryde <[email protected]> Mon, 14 Apr 2008 11:09:34 +1000
| Newsgroups | gmane.comp.lang.perl.modules.html-tableextract |
|---|---|
| Message-ID | <[email protected]> |
--=-=-=
I'm trying to grab the text from a table where some cells have silly
nested 1x1 subtables, like foo.html below.
The easiest way seems to be "tree" mode and the text comes out from
"as_text", but am I right tree mode means all modules in my program
using HTML::TableExtract will get that mode, or can it be turned on and
off?
Otherwise, in plain mode, asking for subtables returns the nested bits
as it should, but I couldn't tell how to associate the subtable with the
cell containing it. In my case I'd be working through each cell and
would want the subtable in it, if any. (Of course presumably there
could be multiple subtables in one cell for really degenerate input.)
--=-=-=
Content-Type: text/html
Content-Disposition: attachment; filename=foo.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body>
<p>
Here's a table:
<p>
<table>
<tr>
<td> headone </td>
<td> headtwo </td>
</tr>
<tr>
<td> <table>
<tr>
<td> <i>elemone</i> </td>
</tr>
</table>
</td>
<td> <b>elemtwo</b> </td>
</tr>
</table>
</p>
</body>
</html>
--=-=-=
Content-Type: text/x-perl
Content-Disposition: attachment; filename=foo.pl
use strict;
use warnings;
require HTML::TableExtract;
open IN, '<foo.html' or die;
my $content = do { local $/ = undef; <IN> }; # slurp
close IN or die;
my $te = HTML::TableExtract->new (headers => ['head'],
keep_headers => 1,
slice_columns => 0,
# subtables => 1,
);
$te->parse ($content);
my $ts = $te->table(0,0);
my $rows_aref = $ts->rows;
my $lastrow = $#$rows_aref;
my $lastcol = $#{$rows_aref->[0]};
foreach my $row (0 .. $lastrow) {
foreach my $col (0 .. $lastcol) {
my $cell = $ts->cell($row,$col) or next;
print "$row,$col text ",$cell,"\n";
}
}
exit 0;
--=-=-=
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
--=-=-=
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Table-extract-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/table-extract-general
--=-=-=--