我制作了一个脚本,它将从 HTML<TR>
标记中提取所有 Row 数据。<TR>
我的 HTML 页面上有 30 个 HTML标签。根据计数,我的代码将获取特定的行数据。假设我需要 5th 中的数据<tr>...</tr>
,那么我的条件是if(count =5) {(go inside and get that data)}
但我的问题是我一次需要一个选定行的数据。假设我需要第 5、6 和 14 行的数据。
你能帮我整理一下吗?
$te = new HTML::TableExtract(count => 0 );
$te->parse($content);
# Examine all matching tables
foreach $ts ($te->table_states) {
#print "Table (", join(',', $ts->coords), "):\n";
$cnt = 1;
foreach $row($ts->rows) {
# print " ---- Printing Row $cnt ----\n";
$PrintLine= join("\t", @$row);
@RowData=split(/\t/,$PrintLine);
$PrintLine =~ s/\r//ig;
$PrintLine =~ s/\t//ig;
$cnt = $cnt + 1;
# if ($PrintLine =~ /Site ID/ig || $PrintLine =~ /Site name/ig){print " Intrest $PrintLine $cnt =====================\n"};
if ( $cnt == 14) {
$arraycnt = 1;
my $SiteID="";
my $SiteName="";
foreach (@RowData) {
# print " Array element $arraycnt\n";
chomp;
$_ =~ s/\r//ig;
$_ =~ s/[\xC3\xA1\xC3\xA0\xC3\xA2\xC3\xA3]//ig;
if ($arraycnt== 17 ) { $SiteID= $_;}
if ($arraycnt== 39 ) { $SiteName= $_;}
$arraycnt = $arraycnt + 1;
}
#$PrintLineFinal = $BridgeCase."\t".$PrintLine;
$PrintLineFinal = $BridgeCase."\t".$SiteID."\t".$SiteName;
#print "$PrintLineFinal\n";
print MYFILE2 "$PrintLineFinal\n";
last;
}
}
}