Here is one way to do it, using HTML::TableExtract (written by our own mojotoad):
use strict; use warnings; use HTML::TableExtract; use Data::Dumper; my $html = <<'EOHTML'; <table cellspacing="0" cellpadding="2" border="0" width="100%"> <tr> <td width="20%" align="right" valign="top" bgcolor="#CCCCCC"> <font face="arial, helvetica" size="2"><b>02:44 AM EDT</b></font><br> <font face="arial, helvetica" size="1">0:42 (est.)</font><br></td> <td valign="top"><font face="arial, helvetica" size= "1">Speech</font><br> <font face="arial, helvetica" size="2"><a href= "/cspan/cspan.csp?command=dprogram&record=142524675">U.S.-Ja +pan Relations</a><br> Asia Society, Washington Center<br></font> <font face= "arial, helvetica" size="2" color="#CC0000">Ryozo Kato</font> <font face="arial, helvetica" size="1">, Japan</font></td> </tr> </table> EOHTML my $te = HTML::TableExtract->new(); $te->parse( $html ); my @datatypes = qw( time length type title org ); foreach my $ts ( $te->table_states ) { foreach my $row ( $ts->rows ) { my @extracted = map { split( /\n\n/, $_ ) } @$row; my %data = map { $datatypes[$_] => clean_whitespace( $extracte +d[$_] ) } ( 0 .. $#datatypes ); print Dumper( \%data ); } } sub clean_whitespace { my ( $text ) = @_; $text =~ s/^\s+//; $text =~ s/\s+$//; $text =~ s/\s+/ /g; return $text; } __OUTPUT__ $VAR1 = { 'org' => 'Asia Society, Washington Center Ryozo Kato , Japan +', 'title' => 'U.S.-Japan Relations', 'length' => '0:42 (est.)', 'type' => 'Speech', 'time' => '02:44 AM EDT' };
In reply to Re: Putting HTML::Element content_list into a hash
by bobf
in thread Putting HTML::Element content_list into a hash
by TsuDohNihm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |