我嘗試將整個網頁保存在我的系統上作爲.HTML文件,然後解析該文件,找到一些標籤並使用它們。我能夠保存/解析http:/ url,但無法保存/解析https:/ url。我正在使用Perl。我使用下面的代碼來保存http,它工作正常。但不適用於https。是否可以解析HTTPS頁面?? ..:使用Perl腳本檢索https://examle.com url
use strict;
use warnings;
use LWP::Simple qw($ua get);
use LWP::UserAgent;
use LWP::Protocol::https;
use HTTP::Cookies;
sub main
{
my $ua = LWP::UserAgent->new();
my $cookies = HTTP::Cookies->new(
file => "cookies.txt",
autosave => 1,
);
$ua->cookie_jar($cookies);
$ua->agent("Google Chrome/30");
#$ua->ssl_opts(SSL_ca_file => 'cert.pfx');
$ua->proxy('http','http://proxy.com');
my $response = $ua->get('http://google.com');
#$ua->credentials($response, "", "usrname", "password");
unless($response->is_success) {
print "Error: " . $response->status_line;
}
# Let's save the output.
my $save = "save.html";
unless(open SAVE, '>' . $save) {
die "nCannot create save file '$save'n";
}
# Without this line, we may get a
# 'wide characters in print' warning.
binmode(SAVE, ":utf8");
print SAVE $response->decoded_content;
close SAVE;
print "Saved ",
length($response->decoded_content),
" bytes of data to '$save'.";
}
main();
運行此單線程的任何錯誤? 'perl -MLWP :: UserAgent -e'$ ua = LWP :: UserAgent-> new; print $ ua-> get(「https://github.com」) - > decode_content();'' – Suic