Web::查询和数据提取 [英] Web::Query and data extraction
本文介绍了Web::查询和数据提取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在从网页中抓取信息时遇到了问题,有人解决了这个问题,但我也想从该结构中获取数据并将其放入普通的字符串变量中,我评论说这个并被告知要创建一个新问题,所以来了!
I had a problem with scraping info from a web page, which was solved by someone, but i would also like to get the data from that structure and put it into normal string variables, i commented saying this and was told to create a new question, so here it is!
代码:
use Web::Query 'wq';
my $football_matches = wq($mech->content)
->find('tr.match')
->map(sub {
my (undef, $e) = @_;
return 'v' eq $e->find('td.score')->text
? [
$e->attr('id'),
map { $e->find("td.$_")->text }
(qw(tournament dateTime homeTeam score awayTeam prices))
]
: ();
});
use Data::Dumper; print Dumper $football_matches;
输出:
$VAR1 = [
['tn7gc635476', '', ' Mo 12Mar 2012 ', 'Arsenal', 'v', 'Newcastle', ' '],
['tn7gc649937', '', ' Tu 13Mar 2012 ', 'Liverpool', 'v', 'Everton', ' '],
['tn7gc635681', '', ' Sa 17Mar 2012 ', 'Fulham', 'v', 'Swansea', ' '],
['tn7gc635661', '', ' Sa 17Mar 2012 ', 'Wigan', 'v', 'West Brom', ' '],
['tn7gc635749', '', ' Su 18Mar 2012 ', 'Wolves', 'v', 'Man Utd', ' '],
['tn7gc635556', '', ' Su 18Mar 2012 ', 'Newcastle', 'v', 'Norwich', ' ']
];
我想做的是将每个日期、主队和客队都放入普通变量/数组中.
What i would like to do is take each date, home team and away team and put them into normal variables/arrays.
提前致谢!
推荐答案
您可能需要查看 perldsc 和 perlref.查找部分 arrays-of-arrays 和 arrayref
You may want to check perldsc and perlref. Look for the part arrays-of-arrays and arrayref
这篇关于Web::查询和数据提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文