我有这段代码:
#!/opt/local/bin/perl
use 5.014;
use warnings;
use Web::Scraper;
use Data::Dumper;
my $html = do { local $/; <DATA> };
my $br = scraper {
process 'div#br-wrap > ul', 'bc[]' => scraper {
process 'li > a', 'link' => '@href';
};
};
my $res = $br->scrape( $html );
say Dumper($res);
__DATA__
<html>
<head><title>title</title></head>
<body>
<div id="content">
<div id="br-wrap">
<ul class="br">
<li><a href="/">Home</a></li>
<li><a href="/sub/xxx">Sub-xxx</a></li>
<li><a href="/sub/xxx/cat/name">Sub-Cat</a></li>
<li><a href="/sub/xxx/item">Sub-Item</a></li>
</ul>
</div>
</div>
</body>
</html>
结果是:
$VAR1 = {
'bc' => [
{
'link' => '/'
}
]
};
但是,我正在寻找链接的 ARRAY ......
$VAR1 = {
'bc' => [
{
'link' => '/'
},
{
'link' => '/sub/xxx'
},
{
'link' => '/sub/xxx/cat/name'
},
{
'link' => '/sub/xxx/item'
}
]
};
代码中的错误在哪里?
答案 0 :(得分:2)
process 'div#br-wrap > ul > li', 'bc[]' => scraper {
process 'a', 'link' => '@href';