weismat has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am using HTML::ElementTable to parse thousands of HTML tables. This works fine if the page fits to my expected structure. I am currently using eval to workaround if the page does not fit to the expected structure, but I would like to make that part better. What is the best way to determine if a table or a cell inside the table exists? Or would you recommend me using a different parsing module? Let me know if you need code examples! Thanks in advance!

Replies are listed 'Best First'.
Re: Error handling with HTML::TableExtract
by svenXY (Deacon) on Oct 17, 2007 at 07:17 UTC
    Hi,
    yes, we need code examples. You don't really expect us to write some script for you without having proper input, desired output and so on, do you?
    Please read How (Not) To Ask A Question to give us a chance to help you by providing a properly described problem.
    Regards,
    svenXY
      Example
      eval { my $url="zzz"; $response = $ua->get($url); if ($response->is_success) { $content=$response->content; } else { next; } $te= HTML::TableExtract->new(keep_html=>0); $te->parse($content); if ($te->table(3,3)->cell(1,0) eq "xxxx") { $a=$te->table(3,3)->cell(1,1); $b=$te->table(3,3)->cell(4,1); } else { $a=$te->table(3,4)->cell(1,1); $b=$te->table(3,4)->cell(4,1); } }; warn $@ if $@; }
      $te->table(3,3) does not exist in all cases and thus I always use eval instead of a proper error handling.
Re: Error handling with HTML::TableExtract
by svenXY (Deacon) on Oct 17, 2007 at 11:50 UTC
    Hi,
    it would have been nice if you'd given an example that included the module calls etc., but anyway, here's some code that works for me. I think it should show you how to get your problem solved.

    Regards,
    svenXY