我試著用Web::Scraper刮取HTML頁面,但令人驚訝的是,我沒有像我預期的那樣從腳本標簽中獲得腳本。
下面的例子
use Web::Scraper;
使用 Data::Dumper。
my $html = q?
<html>
<head>
<title>test html</title>
</head>
<body>
<script>
測驗腳本
</script>
<p>
p測驗
</p>
<other>
其他測驗
</other>
</body>
</html>
|。
our $scraper = scraper {
處理 'script', "script" => 'TEXT';
處理 'p', "p" => 'TEXT';
處理'other', "other" => 'TEXT';
};
my $data = $scraper->scrape( $html ) 。
say Dumper $data;
給出輸出
$VAR1 = {
'other' => ' other test ',
'p' => ' p測驗'。
'script' => ''.
};
作為一個黑客,我可以在搜刮前重命名腳本標簽,但我想了解為什么Web::Scraper不給我行內腳本的內容?或者我應該怎么做呢?
uj5u.com熱心網友回復:
使用XPath運算式對我來說是有效的:
process '//script/text()', "script" => 'TEXT';
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/311351.html
標籤:
