.\" Automatically generated by Pod::Man 2.23 (Pod::Simple 3.18) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "HTML::TableExtract 3pm" .TH HTML::TableExtract 3pm "2011-08-27" "perl v5.12.4" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" HTML::TableExtract \- Perl module for extracting the content contained in tables within an HTML document, either as text or encoded element trees. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& # Matched tables are returned as table objects; tables can be matched \& # using column headers, depth, count within a depth, table tag \& # attributes, or some combination of the four. \& \& # Example: Using column header information. \& # Assume an HTML document with tables that have "Date", "Price", and \& # "Cost" somewhere in a row. The columns beneath those headings are \& # what you want to extract. They will be returned in the same order as \& # you specified the headers since \*(Aqautomap\*(Aq is enabled by default. \& \& use HTML::TableExtract; \& $te = HTML::TableExtract\->new( headers => [qw(Date Price Cost)] ); \& $te\->parse($html_string); \& \& # Examine all matching tables \& foreach $ts ($te\->tables) { \& print "Table (", join(\*(Aq,\*(Aq, $ts\->coords), "):\en"; \& foreach $row ($ts\->rows) { \& print join(\*(Aq,\*(Aq, @$row), "\en"; \& } \& } \& \& # Shorthand...top level rows() method assumes the first table found in \& # the document if no arguments are supplied. \& foreach $row ($te\->rows) { \& print join(\*(Aq,\*(Aq, @$row), "\en"; \& } \& \& # Example: Using depth and count information. \& # Every table in the document has a unique depth and count tuple, so \& # when both are specified it is a unique table. Depth and count both \& # begin with 0, so in this case we are looking for a table (depth 2) \& # within a table (depth 1) within a table (depth 0, which is the top \& # level HTML document). In addition, it must be the third (count 2) \& # such instance of a table at that depth. \& \& $te = HTML::TableExtract\->new( depth => 2, count => 2 ); \& $te\->parse_file($html_file); \& foreach $ts ($te\->tables) { \& print "Table found at ", join(\*(Aq,\*(Aq, $ts\->coords), ":\en"; \& foreach $row ($ts\->rows) { \& print " ", join(\*(Aq,\*(Aq, @$row), "\en"; \& } \& } \& \& # Example: Using table tag attributes. \& # If multiple attributes are specified, all must be present and equal \& # for match to occur. \& \& $te = HTML::TableExtract\->new( attribs => { border => 1 } ); \& $te\->parse($html_string); \& foreach $ts ($te\->tables) { \& print "Table with border=1 found at ", join(\*(Aq,\*(Aq, $ts\->coords), ":\en"; \& foreach $row ($ts\->rows) { \& print " ", join(\*(Aq,\*(Aq, @$row), "\en"; \& } \& } \& \& # Example: Extracting as an HTML::Element tree structure \& # Rather than extracting raw text, the html can be converted into a \& # tree of element objects. The HTML document is composed of \& # HTML::Element objects and the tables are HTML::ElementTable \& # structures. Using this, the contents of tables within a document can \& # be edited in\-place. \& \& use HTML::TableExtract qw(tree); \& $te = HTML::TableExtract\->new( headers => qw(Fee Fie Foe Fum) ); \& $te\->parse_file($html_file); \& $table = $te\->first_table_found; \& $table_tree = $table\->tree; \& $table_tree\->cell(4,4)\->replace_content(\*(AqGolden Goose\*(Aq); \& $table_html = $table_tree\->as_HTML; \& $table_text = $table_tree\->as_text; \& $document_tree = $te\->tree; \& $document_html = $document_tree\->as_HTML; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" HTML::TableExtract is a subclass of HTML::Parser that serves to extract the information from tables of interest contained within an \s-1HTML\s0 document. The information from each extracted table is stored in table objects. Tables can be extracted as text, \s-1HTML\s0, or HTML::ElementTable structures (for in-place editing or manipulation). .PP There are currently four constraints available to specify which tables you would like to extract from a document: \fIHeaders\fR, \fIDepth\fR, \&\fICount\fR, and \fIAttributes\fR. .PP \&\fIHeaders\fR, the most flexible and adaptive of the techniques, involves specifying text in an array that you expect to appear above the data in the tables of interest. Once all headers have been located in a row of that table, all further cells beneath the columns that matched your headers are extracted. All other columns are ignored: think of it as vertical slices through a table. In addition, TableExtract automatically rearranges each row in the same order as the headers you provided. If you would like to disable this, set \fIautomap\fR to 0 during object creation, and instead rely on the \fIcolumn_map()\fR method to find out the order in which the headers were found. Furthermore, TableExtract will automatically compensate for cell span issues so that columns are really the same columns as you would visually see in a browser. This behavior can be disabled by setting the \fIgridmap\fR parameter to 0. \s-1HTML\s0 is stripped from the entire textual content of a cell before header matches are attempted \*(-- unless the \fIkeep_html\fR parameter was enabled. .PP \&\fIDepth\fR and \fICount\fR are more specific ways to specify tables in relation to one another. \fIDepth\fR represents how deeply a table resides in other tables. The depth of a top-level table in the document is 0. A table within a top-level table has a depth of 1, and so on. Each depth can be thought of as a layer; tables sharing the same depth are on the same layer. Within each of these layers, \&\fICount\fR represents the order in which a table was seen at that depth, starting with 0. Providing both a \fIdepth\fR and a \fIcount\fR will uniquely specify a table within a document. .PP \&\fIAttributes\fR match based on the attributes of the html tag, for example, boder widths or background color. .PP Each of the \fIHeaders\fR, \fIDepth\fR, \fICount\fR, and \fIAttributes\fR specifications are cumulative in their effect on the overall extraction. For instance, if you specify only a \fIDepth\fR, then you get all tables at that depth (note that these could very well reside in separate higher\- level tables throughout the document since depth extends across tables). If you specify only a \fICount\fR, then the tables at that \fICount\fR from all depths are returned (i.e., the \fIn\fRth occurrence of a table at each depth). If you only specify \fIHeaders\fR, then you get all tables in the document containing those column headers. If you have specified multiple constraints of \fIHeaders\fR, \fIDepth\fR, \fICount\fR, and \fIAttributes\fR, then each constraint has veto power over whether a particular table is extracted. .PP If no \fIHeaders\fR, \fIDepth\fR, \fICount\fR, or \fIAttributes\fR are specified, then all tables match. .PP When extracting only text from tables, the text is decoded with HTML::Entities by default; this can be disabled by setting the \fIdecode\fR parameter to 0. .SS "Extraction Modes" .IX Subsection "Extraction Modes" The default mode of extraction for HTML::TableExtract is raw text or \&\s-1HTML\s0. In this mode, embedded tables are completely decoupled from one another. In this case, HTML::TableExtract is a subclass of HTML::Parser: .PP .Vb 1 \& use HTML::TableExtract; .Ve .PP Alternativevly, tables can be extracted as HTML::ElementTable structures, which are in turn embedded in an HTML::Element tree representing the entire \s-1HTML\s0 document. Embedded tables are not decoupled from one another since this tree structure must be manitained. In this case, HTML::TableExtract is a subclass of HTML::TreeBuilder (itself a subclass of HTML:::Parser): .PP .Vb 1 \& use HTML::TableExtract qw(tree); .Ve .PP In either case, the basic interface for HTML::TableExtract and the resulting table objects remains the same \*(-- all that changes is what you can do with the resulting data. .PP HTML::TableExtract is a subclass of HTML::Parser, and as such inherits all of its basic methods such as \f(CW\*(C`parse()\*(C'\fR and \f(CW\*(C`parse_file()\*(C'\fR. During scans, \f(CW\*(C`start()\*(C'\fR, \f(CW\*(C`end()\*(C'\fR, and \f(CW\*(C`text()\*(C'\fR are utilized. Feel free to override them, but if you do not eventually invoke them in the \s-1SUPER\s0 class with some content, results are not guaranteed. .SS "Advice" .IX Subsection "Advice" The main point of this module was to provide a flexible method of extracting tabular information from \s-1HTML\s0 documents without relying to heavily on the document layout. For that reason, I suggest using \&\fIHeaders\fR whenever possible \*(-- that way, you are anchoring your extraction on what the document is trying to communicate rather than some feature of the \s-1HTML\s0 comprising the document (other than the fact that the data is contained in a table). .SH "METHODS" .IX Header "METHODS" The following are the top-level methods of the HTML::TableExtract object. Tables that have matched a query are actually returned as separate objects of type HTML::TableExtract::Table. These table objects have their own methods, documented further below. .SS "\s-1CONSTRUCTOR\s0" .IX Subsection "CONSTRUCTOR" .IP "\fInew()\fR" 4 .IX Item "new()" Return a new HTML::TableExtract object. Valid attributes are: .RS 4 .IP "headers" 4 .IX Item "headers" Passed as an array reference, headers specify strings of interest at the top of columns within targeted tables. They can be either strings or regular expressions (qr//). If they are strings, they will eventually be passed through a non-anchored, case-insensitive regular expression, so regexp special characters are allowed. .Sp The table row containing the headers is \fBnot\fR returned, unless \&\f(CW\*(C`keep_headers\*(C'\fR was specified or you are extracting into an element tree. In either case the header row can be accessed via the \fIhrow()\fR method from within the table object. .Sp Columns that are not beneath one of the provided headers will be ignored unless \f(CW\*(C`slice_columns\*(C'\fR was set to 0. Columns will, by default, be rearranged into the same order as the headers you provide (see the \&\fIautomap\fR parameter for more information) \fIunless\fR \f(CW\*(C`slice_columns\*(C'\fR is 0. .Sp Additionally, by default columns are considered what you would see visually beneath that header when the table is rendered in a browser. See the \f(CW\*(C`gridmap\*(C'\fR parameter for more information. .Sp \&\s-1HTML\s0 within a header is stripped before the match is attempted, unless the \f(CW\*(C`keep_html\*(C'\fR parameter was specified and \&\f(CW\*(C`strip_html_on_match\*(C'\fR is false. .IP "depth" 4 .IX Item "depth" Specify how embedded in other tables your tables of interest should be. Top-level tables in the \s-1HTML\s0 document have a depth of 0, tables within top-level tables have a depth of 1, and so on. .IP "count" 4 .IX Item "count" Specify which table within each depth you are interested in, beginning with 0. .IP "attribs" 4 .IX Item "attribs" Passed as a hash reference, attribs specify attributes of interest within the \s-1HTML\s0
tag itself. .IP "automap" 4 .IX Item "automap" Automatically applies the ordering reported by \fIcolumn_map()\fR to the rows returned by \fIrows()\fR. This only makes a difference if you have specified \&\fIHeaders\fR and they turn out to be in a different order in the table than what you specified. Automap will rearrange the columns in the same order as the headers appear. To get the original ordering, you will need to take another slice of each row using \fIcolumn_map()\fR. \fIautomap\fR is enabled by default. .IP "slice_columns" 4 .IX Item "slice_columns" Enabled by default, this option controls whether vertical slices are returned from under headers that match. When disabled, all columns of the matching table are retained, regardles of whether they had a matching header above them. Disabling this also disables \f(CW\*(C`automap\*(C'\fR. .IP "keep_headers" 4 .IX Item "keep_headers" Disabled by default, and only applicable when header constraints have been specified, \f(CW\*(C`keep_headers\*(C'\fR will retain the matching header row as the first row of table data when enabled. This option has no effect if extracting into an element tree tructure. In any case, the header row is accessible from the table method \f(CW\*(C`hrow()\*(C'\fR. .IP "gridmap" 4 .IX Item "gridmap" Controls whether the table contents are returned as a grid or a tree. \&\s-1ROWSPAN\s0 and \s-1COLSPAN\s0 issues are compensated for, and columns really are columns. Empty phantom cells are created where they would have been obscured by \s-1ROWSPAN\s0 or \s-1COLSPAN\s0 settings. This really becomes an issue when extracting columns beneath headers. Enabled by default. .IP "subtables" 4 .IX Item "subtables" Extract all tables embedded within matched tables. .IP "decode" 4 .IX Item "decode" Automatically decode retrieved text with \&\fIHTML::Entities::decode_entities()\fR. Enabled by default. Has no effect if \&\f(CW\*(C`keep_html\*(C'\fR was specified or if extracting into an element tree structure. .IP "br_translate" 4 .IX Item "br_translate" Translate
tags into newlines. Sometimes the remaining text can be hard to parse if the
tag is simply dropped. Enabled by default. Has no effect if \fIkeep_html\fR is enabled or if extracting into an element tree structure. .IP "keep_html" 4 .IX Item "keep_html" Return the raw \s-1HTML\s0 contained in the cell, rather than just the visible text. Embedded tables are \fBnot\fR retained in the \s-1HTML\s0 extracted from a cell. Patterns for header matches must take into account \s-1HTML\s0 in the string if this option is enabled. This option has no effect if extracting into an elment tree structure. .IP "strip_html_on_match" 4 .IX Item "strip_html_on_match" When \f(CW\*(C`keep_html\*(C'\fR is enabled, \s-1HTML\s0 is stripped by default during attempts at matching header strings (so if \f(CW\*(C`strip_html_on_match\*(C'\fR is not enabled and \f(CW\*(C`keep_html\*(C'\fR is, you would have to include potential \s-1HTML\s0 tags in the regexp for header matches). Stripped header tags are replaced with an empty string, e.g. 'hot dog' would become 'hot dog' before attempting a match. .IP "error_handle" 4 .IX Item "error_handle" Filehandle where error messages are printed. \s-1STDERR\s0 by default. .IP "debug" 4 .IX Item "debug" Prints some debugging information to \s-1STDERR\s0, more for higher values. If \f(CW\*(C`error_handle\*(C'\fR was provided, messages are printed there rather than \s-1STDERR\s0. .RE .RS 4 .RE .SS "\s-1REGULAR\s0 \s-1METHODS\s0" .IX Subsection "REGULAR METHODS" The following methods are invoked directly from an HTML::TableExtract object. .IP "\fIdepths()\fR" 4 .IX Item "depths()" Returns all depths that contained matched tables in the document. .IP "counts($depth)" 4 .IX Item "counts($depth)" For a particular depth, returns all counts that contained matched tables. .ie n .IP "table($depth, $count)" 4 .el .IP "table($depth, \f(CW$count\fR)" 4 .IX Item "table($depth, $count)" For a particular depth and count, return the table object for the table found, if any. .IP "\fItables()\fR" 4 .IX Item "tables()" Return table objects for all tables that matched. Returns an empty list if no tables matched. .IP "\fIfirst_table_found()\fR" 4 .IX Item "first_table_found()" Return the table state object for the first table matched in the document. Returns undef if no tables were matched. .IP "\fIcurrent_table()\fR" 4 .IX Item "current_table()" Returns the current table object while parsing the \s-1HTML\s0. Only useful if you're messing around with overriding HTML::Parser methods. .IP "\fItree()\fR" 4 .IX Item "tree()" If the module was invoked in tree extraction mode, returns a reference to the top node of the HTML::Element tree structure for the entire document (which includes, ultimately, all tables within the document). .ie n .IP "tables_report([$show_content, $col_sep])" 4 .el .IP "tables_report([$show_content, \f(CW$col_sep\fR])" 4 .IX Item "tables_report([$show_content, $col_sep])" Return a string summarizing extracted tables, along with their depth and count. Optionally takes a \f(CW$show_content\fR flag which will dump the extracted contents of each table as well with columns separated by \&\f(CW$col_sep\fR. Default \f(CW$col_sep\fR is ':'. .ie n .IP "tables_dump([$show_content, $col_sep])" 4 .el .IP "tables_dump([$show_content, \f(CW$col_sep\fR])" 4 .IX Item "tables_dump([$show_content, $col_sep])" Same as \f(CW\*(C`tables_report()\*(C'\fR except dump the information to \s-1STDOUT\s0. .IP "start" 4 .IX Item "start" .PD 0 .IP "end" 4 .IX Item "end" .IP "text" 4 .IX Item "text" .PD These are the hooks into HTML::Parser. If you want to subclass this module and have things work, you must at some point call these with content. .SS "\s-1DEPRECATED\s0 \s-1METHODS\s0" .IX Subsection "DEPRECATED METHODS" Tables used to be called 'table states'. Accordingly, the following methods still work but have been deprecated: .IP "\fItable_state()\fR" 4 .IX Item "table_state()" Is now \fItable()\fR .IP "\fItable_states()\fR" 4 .IX Item "table_states()" Is now \fItables()\fR .IP "\fIfirst_table_state_found()\fR" 4 .IX Item "first_table_state_found()" Is now \fIfirst_table_found()\fR .SS "\s-1TABLE\s0 \s-1METHODS\s0" .IX Subsection "TABLE METHODS" The following methods are invoked from an HTML::TableExtract::Table object, such as those returned from the \f(CW\*(C`tables()\*(C'\fR method. .IP "\fIrows()\fR" 4 .IX Item "rows()" Return all rows within a matched table. Each row returned is a reference to an array containing the text, \s-1HTML\s0, or reference to the HTML::Element object of each cell depending the mode of extraction. Tables with rowspan or colspan attributes will have some cells containing undef. Returns a list or a reference to an array depending on context. .IP "\fIcolumns()\fR" 4 .IX Item "columns()" Return all columns within a matched table. Each column returned is a reference to an array containing the text, \s-1HTML\s0, or reference to HTML::Element object of each cell depending on the mode of extraction. Tables with rowspan or colspan attributes will have some cells containing undef. .IP "row($row)" 4 .IX Item "row($row)" Return a particular row from within a matched table either as a list or an array reference, depending on context. .IP "column($col)" 4 .IX Item "column($col)" Return a particular column from within a matched table as a list or an array reference, depending on context. .IP "cell($row,$col)" 4 .IX Item "cell($row,$col)" Return a particular item from within a matched table, whether it be the text, \s-1HTML\s0, or reference to the HTML::Element object of that cell, depending on the mode of extraction. If the cell was covered due to rowspan or colspan effects, will return undef. .IP "space($row,$col)" 4 .IX Item "space($row,$col)" The same as \fIcell()\fR, except in cases where the given coordinates were covered due to rowspan or colspan issues, in which case the content of the covering cell is returned rather than undef. .IP "\fIdepth()\fR" 4 .IX Item "depth()" Return the depth at which this table was found. .IP "\fIcount()\fR" 4 .IX Item "count()" Return the count for this table within the depth it was found. .IP "\fIcoords()\fR" 4 .IX Item "coords()" Return depth and count in a list. .IP "\fItree()\fR" 4 .IX Item "tree()" If the module was invoked in tree extraction mode, this accessor provides a reference to the HTML::ElementTable structure encompassing the table. .IP "\fIhrow()\fR" 4 .IX Item "hrow()" Returns the header row as a list when headers were specified as a constraint. If \f(CW\*(C`keep_headers\*(C'\fR was specified initially, this is equivalent to the first row returned by the \f(CW\*(C`rows()\*(C'\fR method. .IP "\fIcolumn_map()\fR" 4 .IX Item "column_map()" Return the order (via indices) in which the provided headers were found. These indices can be used as slices on rows to either order the rows in the same order as headers or restore the rows to their natural order, depending on whether the rows have been pre-adjusted using the \&\fIautomap\fR parameter. .IP "\fIlineage()\fR" 4 .IX Item "lineage()" Returns the path of matched tables that led to matching this table. The path is a list of array refs containing depth, count, row, and column values for each ancestor table involved. Note that corresponding table objects will not exist for ancestral tables that did not match specified constraints. .SH "NOTES ON TREE EXTRACTION MODE" .IX Header "NOTES ON TREE EXTRACTION MODE" As mentioned above, HTML::TableExtract can be invoked in 'tree' mode where the resulting \s-1HTML\s0 and extracted tables are encoded in HTML::Element tree structures: .PP .Vb 1 \& use HTML::TableExtract \*(Aqtree\*(Aq; .Ve .PP There are a number of things to take note of while using this mode. The entire \s-1HTML\s0 document is encoded into an HTML::Element tree. Each table is part of this structure, but nevertheless is tracked separately via an HTML::ElementTable structure, which is a specialized form of HTML::Element tree. .PP The HTML::ElementTable objects are accessible by invoking the \fItree()\fR method from within each table object returned by HTML::TableExtract. The HTML::ElementTable objects have their own \fIrow()\fR, \fIcol()\fR, and \fIcell()\fR methods (among others). These are not to be confused with the \fIrow()\fR and \&\fIcolumn()\fR methods provided by the HTML::TableExtract::Table objects. .PP For example, the \fIrow()\fR method from HTML::ElementTable will provide a reference to a 'glob' of all the elements in that row. Actions (such as setting attributes) performed on that row reference will affect all elements within that row. On the other hand, the \fIrow()\fR method from the HTML::TableExtract::Table object will return an array (either by reference or list, depending on context) of the contents of each cell within the row. In tree mode, the content is represented by individual references to each cell \*(-- these are references to the same HTML::Element objects that reside in the HTML::Element tree. .PP The \fIcell()\fR methods provided in both cases will therefore return references to the same object. The exception to this is when a 'cell' in the table grid was originally 'covered' due to rowspan or colspan issues \&\*(-- in this case the cell content will be undef. Likewise, the \fIrow()\fR or \&\fIcolumn()\fR methods from HTML::TableExtract::Table objects will return arrays potentially containing a mixture of object references and undefs. If you're going to be doing lots of manipulation of the table elements, it might be more efficient to access them via the methods provided by the HTML::ElementTable object instead. See HTML::ElementTable for more information on how to manipulate those objects. .PP An alternative to the \fIcell()\fR method in HTML::TableExtract::Table is the \&\fIspace()\fR method. It is largely similar to \fIcell()\fR, except when given coordinates of a cell that was covered due to rowspan or colspan effects, it will return the contents of the cell that was covering that space rather than undef. So if, for example, cell (0,0) had a rowspan of 2 and colspan of 2, cell(1,1) would return undef and space(1,1) would return the same content as cell(0,0) or space(0,0). .SH "REQUIRES" .IX Header "REQUIRES" \&\fIHTML::Parser\fR\|(3), \fIHTML::Entities\fR\|(3) .SH "OPTIONALLY REQUIRES" .IX Header "OPTIONALLY REQUIRES" \&\fIHTML::TreeBuilder\fR\|(3), \fIHTML::ElementTable\fR\|(3) .SH "AUTHOR" .IX Header "AUTHOR" Matthew P. Sisk, <\fIsisk@mojotoad.com\fR> .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (c) 2000\-2006 Matthew P. Sisk. All rights reserved. All wrongs revenged. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fIHTML::Parser\fR\|(3), \fIHTML::TreeBuilder\fR\|(3), \fIHTML::ElementTable\fR\|(3), \fIperl\fR\|(1).