在真正的Firefox浏览器中,我通过“ https://www.briefing.com/Login/subscriber.aspx”进行的身份验证在我的硬盘上放置了一个cookie。然后,当我开始另一个会话时,我可以绕过身份验证步骤,直接进入“ https://www.briefing.com/investor/calendars/earnings/2018/08/09”之类的数据页面。
在下面的代码中,我试图复制上面的内容,但无济于事。我在做什么错了?
use strict;
use warnings;
use HTTP::Cookies;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
# Let ua use cookies and gives it an empty jar
$ua->cookie_jar(HTTP::Cookies->new());
# login to create cookies
# The field names are guessed, based on these web elements:
# <input name="_textBoxUserName" id="_textBoxUserName" type="text">
# <input name="_textBoxPassword" id="_textBoxPassword" type="password">
my $url = 'https://www.briefing.com/Login/subscriber.aspx';
my $res = $ua->post($url,
'_textBoxUserName' => '*******',
'_textBoxPassword' => '*******');
# confirm that new cookies are indeed placed in the cookie jar
print join("\n", $ua->cookie_jar()->as_string);
# But URL still gets re-directed even though the cookie jar has been filled
$url = 'https://www.briefing.com/investor/calendars/earnings/2018/08/09';
$res = $ua->get($url);
print $res->content;