in reply to Fetching a table data in a HMTL file

Use LWP::Simple to download the html file, assuming you need to.

Then use HTML::TableExtract to extract the table data. If that's insufficient, then you can also use heavier parsers like HTML::Parser.

- Miller

  • Comment on Re: Fetching a table data in a HMTL file

Replies are listed 'Best First'.
Re^2: Fetching a table data in a HMTL file
by chrestomanci (Priest) on Mar 22, 2011 at 09:28 UTC

    I prefer to use HTML::TreeBuilder. For example, this code will pull out the table on the PerlMonks home page that lists the currently logged in users:

    use 5.010; use warnings; use strict; use HTML::TreeBuilder; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $fetch_result = $ua->get("http://www.perlmonks.org"); my $tree = HTML::TreeBuilder->new_from_content($fetch_result->content) +; my $nodelet_table = $tree->look_down( '_tag' => 'table', 'id'=>'nodele +t_container' ); my $other_users_cell = $nodelet_table->look_down('id'=>'Other_Users'); my @other_users_list = $other_users_cell->look_down('_tag'=>'li'); print "User logged into PerlMonks:\n"; foreach my $user_element ( @other_users_list ) { print "\t".$user_element->as_text."\n"; }
      thanks chrestomanci !!! i'm feeling lucky :)