|
assuming $html contains html string.
Use HTML::TableContentParser;
print ExtractTable($html,$selectedtable,$selectedrow,$selectedcol);
sub ExtractTable()
{
my $inbuf = shift;
my $SelTable = shift;
my $SelRow = shift;
my $SelCol = shift;
my $outbuf = "";
my $iTblNo = 0;
my $iRwNo = 0;
my $iColNo = 0;
$p = HTML::TableContentParser->new();
$tables = $p->parse($inbuf);
$iTblNo = 0;
for $t (@$tables)
{
if ( ($SelTable == -1) || ($iTblNo == $SelTable ) )
{
$iRwNo = 0;
for $r (@{$t->{rows}})
{
if ( ( $SelRow == -1 ) || ( $iRwNo == $SelRow ) )
{
$line = "";
$iColNo = 0;
for $c (@{$r->{cells}})
{
if ( ( $SelCol == -1 ) || ( $iColNo == $SelCol ) )
{
$celldata = $c->{data};
$line = $line . sprintf "%s|",$celldata;
}
$iColNo++;
}
$line =~ s/\|$//gi;
$outbuf = $outbuf ."$line\n";
}
$iRwNo++;
}
}
$iTblNo++;
}
return $outbuf;
}
|
|