我是 Perl 脚本的新手。我想解析一个文本文件,对解析后的文本进行编码并附加在 URL 中。如果您知道任何资源,请指出我正确的资源。这是我的主要问题。
现在,我尝试使用 Perl 中的 LWP 模块运行 URL 并将其保存在文本文件中。我使用以下程序连接到 Google,但收到“401 UNAUTHORIZED”错误。请帮忙 - 我应该在哪里提供我的用户身份验证详细信息和密码?
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request::Common qw(GET);
use HTTP::Cookies;
my $ua = LWP::UserAgent->new;
# Define user agent type
$ua->agent('Mozilla/8.0');
# Cookies
$ua->cookie_jar(
HTTP::Cookies->new(
file => 'mycookies.txt',
autosave => 1
)
);
# Request object
my $req = GET 'http://www.google.com';
# Make the request
my $res = $ua->request($req);
# Check the response
if ($res->is_success) {
print $res->content;
} else {
print $res->status_line . "\n";
}
exit 0;