gpt4 book ai didi

Perl - Web::Scraper - 链接数组

转载 作者:行者123 更新时间:2023-12-01 00:11:22 26 4
gpt4 key购买 nike

我有这个代码:

#!/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'
}
]
};

代码哪里出错了?

最佳答案

process 'div#br-wrap > ul > li', 'bc[]' => scraper {
process 'a', 'link' => '@href';

关于Perl - Web::Scraper - 链接数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10180095/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com