麻烦在Perl中组合某些数组(web :: scraper)

时间:2014-03-12 18:52:02

标签: perl web-scraping

所以,我在业余时间尝试学习Perl,并且我已经观看了很多教程并阅读了一些材料。

我试图将这些阵列组合在一起(不是我为了简洁而剪掉了一些其他的刮刀块,它们经过测试和工作,并且类似于给出的PCMAG刮刀)

#PCMAG
my $pcmag1_items = scraper {
    process ".news-content", "pcmag1_items[]" => scraper {
        process "h3", title => 'TEXT';
        process "p", body => 'TEXT';
        process ".time-stamp", date => 'TEXT';
        process 'a', link => '@href';   
    };  
};
my $pcmag2_items = scraper {
    process ".news-reviews > ul > li", "pcmag2_items[]" => scraper {
        process "h3", title => 'TEXT';
        process "p", body => 'TEXT';
        process ".time-stamp", date => 'TEXT';
        process 'a', link => '@href';   
    };  
};
my $pcmag1_res = $pcmag1_items->scrape( URI->new("http://www.pcmag.com/news"));
my $pcmag2_res = $pcmag2_items->scrape( URI->new("http://www.pcmag.com/news"));


#MAIN
my @items = (@{$pcmag1_res->{pcmag1_items}}, @{$pcmag2_res->{pcmag2_items}}, @{$cnn_res->{cnn_items}}, @{$cnet_res->{cnet_items}});

for my $item (@items) {
    print "$item->{title} $item->{body} $item->{date} (link: $item->{link})\n \n";
}

我得到的错误是:

greg@Linux:~/Desktop/Perl$ perl scraper2.pl
Use of uninitialized value $xpath in concatenation (.) or string at /usr/local/share/perl/5.14.2/Web/Scraper.pm line 136.
'' doesn't look like a valid XPath expression: Not a _primary_expr at 
greg@Linux:~/Desktop/Perl$ 

0 个答案:

没有答案