如何在这个perl脚本中使HTML :: Clean模块工作。
#!/usr/bin/env perl
use strict;
use warnings;
require LWP::UserAgent;
open FH, "<", "text.txt";
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
foreach my $line (<FH>) {
my $response = $ua->get($line);
my $h = new HTML::Clean(\$response);
if ($response->is_success) {
print $response->decoded_content;
}
else {
die $response->status_line;
}
}
close FH;
答案 0 :(得分:3)
HTML::Clean构造函数方法接受一个参数,该参数是文件名或对包含HTML的字符串的引用。你似乎传递了一个HTTP::Response对象。尝试将HTML传递给它。
my $response = $ua->get($line);
my $html = $response->decoded_content;
my $h = HTML::Clean->new(\$html);