我试图用Web::Scraper抓取HTML-page,但令人惊讶的是,我没有像我预期的那样从脚本标记中获得脚本。
下面的例子
use Web::Scraper;
use Data::Dumper;
my $html = q|
<html>
<head>
<title>test html</title>
</head>
<body>
<script>
test script
</script>
<p>
p test
</p>
<other>
other test
</other>
</body>
</html>
|;
our $scraper = scraper {
process 'script', "script" => 'TEXT';
process 'p', "p" => 'TEXT';
process 'other', "other" => 'TEXT';
};
my $data = $scraper->scrape( $html );
say Dumper $data;给出输出
$VAR1 = {
'other' => ' other test ',
'p' => ' p test ',
'script' => ''
};作为一个技巧,我可以在抓取之前重命名脚本标记,但我想知道为什么Web::Scraper不能给我提供内联脚本的内容?或者我应该做什么不同的事情?
发布于 2021-08-28 05:21:43
它适用于我使用XPath表达式:
process '//script/text()', "script" => 'TEXT';https://stackoverflow.com/questions/68960052
复制相似问题