我製作了一個腳本,它將從HTML <TR>
標籤中提取所有行數據。我的HTML頁面上有30個HTML <TR>
標籤。基於計數,我的代碼將獲取特定的行數據。假設我需要第5個<tr>...</tr>
中的數據,那麼我的條件是if(count =5) {(go inside and get that data)}
用HTML提取幾行:: TableExtract
但是我的問題在於我需要一次選擇一行數據。假設我需要第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;
}
}
}
得益於正確縮進代碼。 – 2013-02-25 20:11:46