For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > November 2005 > HTML::TableExtract example









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author HTML::TableExtract example
Steve Finkelstein

2005-11-23, 6:56 pm

Hi all,

I've completed this using regular expressions parsing out arbitrary data
between HTML tag, however I found a much more efficient route with the
HTML::TableExtract module which looks like it can very well shorten my code
and make it more manageable. I'm able to parse out the entire table with
the following code:

#!/usr/bin/perl -w -t
# Development grounds for using HTML::TableExtract for songsearch.pl

use HTML::TableExtract;
use strict;

my $html = 'latest_rel.htm';

my $te = HTML::TableExtract->new( attribs => { border => 1 } );
$te->parse_file($html);

foreach my $ts ($te->tables) {
foreach my $row ($ts->rows) {
print " ", join(',' , @$row), "\n";
}
}

However, now I want to extract only the second column from this table (It
just consists of several rows with three columns).

Any hints would be greatly appreciated!

Thanks and have a great holiday wend.


--
Steve Finkelstein
stevefink@gmail.com

usenet@DavidFilmer.com

2005-11-23, 6:56 pm

Steve Finkelstein wrote:
> print " ", join(',' , @$row), "\n";


> However, now I want to extract only the second column from this table (It
> just consists of several rows with three columns).


Since you didn't provide a sample of your input data, I can't
test/verify, but it seems you ought to be able to simply say: $$row[1]

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com