Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

In the code snippet below everything seems to work fine.
The HTML file is a saved web page with a table.
The HTML sting is parsed correctly into $tree2.
$table1 is extracted from $tree2 and
the $row_cnt varible is set correctly to 111 rows.
However, the $table->cell($i, 9) method returns
the following when I print the contents of $cell1:

111 rows found
start the row loop
check opening date cell in row: 1
cell1 --> HTML::ElementTable::DataElement=HASH(0x2e4b6ec)

It should return a date like 02-25-2013 but never does.
How do I get a string instead of a hash?
Any thoughts will help.

#!perl -w use HTML::TableExtract qw(tree); use File::Slurp qw( :all ) ; $date = '02-25-2013'; $Path = 'C://path//to//File.htm'; $html_string = read_file($Path); my $tree2 = HTML::TableExtract->new( keep_html => 1, headers => [qw(NSN)], slice_columns => 0, keep_headers => 0, gridmap => 0, strip_html_on_match => 1, debug => 1, decode => 1 ); $tree2->parse($html_string); $table1 = $tree2->first_table_found; my @rows = $table1->rows; my $row_cnt = @rows; print "$row_cnt rows found \n"; my $cell1; my $i = 1; # row number, skip the header row print "start the row loop \n"; while ($i < $row_cnt ) { print "checking date in cell 9 in row: $i \n"; my $cell1 = $table1->cell($i, 9); #row $i, column 9 print "cell1 --> $cell1 \n"; next if $cell1 !~ /$date/; # not today # # there is more code that does not # appear here to save some data from the row # to a file # } continue { $i++; }

In reply to Using HTML::TableExtract cell method by halweitz

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (15)
    As of 2015-07-06 12:41 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (74 votes), past polls