Site menu:

Back to examples

Perl Example - Extract data from html table

#################################################
#Version 0.1                                    #
#Free to use for any purpose                    #
#No credits or backlink required                #
#Author : Shaji Kalidasan (shajiindia@yahoo.com)#
#################################################

use strict;
use warnings;
use HTML::TableExtract;

my $headers = ['Match Number', 'Place', 'Status', 'Result'];

my $table_extract = HTML::TableExtract->new(headers => $headers);

$table_extract->parse_file('table.html');
my ($table) = $table_extract->tables;

for my $row ($table->rows) {
    print join(",", @$row), "\n";
}

__DATA__
#Sample Input HTML File (Shows the content of table.html)


India - Australia Series


One Day International
Match NumberPlaceStatusResult
1AdelaideWonIndia won by 23 runs
2SydneyLostAustralia won by 62 runs
3MelbourneWonIndia won by 3 wickets
4BrisbaneWonIndia won by 76 runs