in reply to Re^3: HTML::TableExtract (parse table column from an HTML page)
in thread HTML::TableExtract (parse table column from an HTML page)

I made a local HTML test page to be parsed with my Perl script, this is my Perl code:
#!/usr/bin/perl use WWW::Mechanize; use HTML::TableExtract; sub parse { $mech = WWW::Mechanize->new(autocheck => 1); $mech->get("file:///home/cafaro/omertascript/test.html"); $content = $mech->content(); $te = HTML::TableExtract->new(depth => 0); $te->parse($content); $table = $te->first_table_found; $tree = $table->tree; print $tree->cell(0,0); } parse();
... and this is my HTML code:
<html> <head> <title>test page</title> <head> <body> <table> <tr><td>parse me</td></tr> </table> </body> </html>

Replies are listed 'Best First'.
Re^5: HTML::TableExtract (parse table column from an HTML page)
by erroneousBollock (Curate) on Oct 07, 2007 at 11:40 UTC
    And did you print $content to see that it contains what you think ? (local and remote versions)

    -David

      print "$content\n"; gives me:
      <html> <head> <title>test page</title> <head> <body> <table> <tr><td>parse me</td></tr> </table> </body> </html>
Re^5: HTML::TableExtract (parse table column from an HTML page)
by Not_a_Number (Prior) on Oct 07, 2007 at 12:40 UTC

    Change your second line to:

    use HTML::TableExtract qw( tree );

    You also need to change your print line to:

    print $tree->cell(0,0)->as_text;
      I'm still getting an error with these modifications: "Can't call method "tree" on unblessed reference"
        The only reason you'd get that is if $table is not returned from $te->first_table_found.

        Try this to see whether HTML::TableExtract (which ISA HTML::Parser) has correctly parsed the HTML:

          $te->parse($content) || die "couldn't parse HTML\n";

        -David

        Well it works for me (whereas with your code I get the same error as you).