一行我已經Perl的以下,結果文件僅打印使用Perl
open (FILE, 'file.htm');
my $tree = HTML::TreeBuilder->new_from_content(do { local $/; <FILE> });
for ($tree->look_down('class' => 'postbody'))
{
my $location = $_->look_down('class' => 'posthilit')->as_trimmed_text;
my $comment = $_->look_down('class' => 'content')->as_trimmed_text;
my $name = $_->look_down('_tag' => 'h3')->as_text;
$name =~ s/^Re:\s*//; $name =~ s/\s*$location\s*$//;
print "Name: $name\nLives in: $location\nCommented: $comment\n";
my $csv = Text::CSV->new();
$csv->column_names('field1', 'field2', 'field3');
$csv->print ($fh, [$name,$location,$comment]);
open $fh, ">", "file.csv" or die "ERROR: $!";
close $fh or die "$!";
}
這僅輸出一個從輸入文件到新的「FILE.CSV」文件中的行。 我怎樣才能得到它把所有的結果放到結果文件中。
在此先感謝。
'$ name','$ location'和'$ comment'從哪裏來? – Toto
我已經在腳本的其餘部分添加了 – Ebikeneser