为什么 Web::Scraper 不解析脚本标签?
Why Web::Scraper does not parse script-tag?
我试图用 Web::Scraper 抓取 HTML-页面,但令人惊讶的是我没有像我预期的那样从脚本标签中获取脚本。
下面的例子
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 没有给我内联脚本的内容?或者我应该怎么做?
它适用于我使用 XPath 表达式:
process '//script/text()', "script" => 'TEXT';
我试图用 Web::Scraper 抓取 HTML-页面,但令人惊讶的是我没有像我预期的那样从脚本标签中获取脚本。
下面的例子
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 没有给我内联脚本的内容?或者我应该怎么做?
它适用于我使用 XPath 表达式:
process '//script/text()', "script" => 'TEXT';