我是 perl 新手,我已经开始使用 mechanize。
我成功登录了一个网站,但之后我想在 Windows 的浏览器中打开该网站,它只是打开该网站,而不是在登录后打开。
#!/usr/bin/perl -w
use Win32::API;
use WWW::Mechanize;
use strict;
use diagnostics;
use warnings;
my $m = WWW::Mechanize->new(
autocheck => 1,
onerror => \&Carp::croak,);
my $Email = 'username';
my $Password = 'password';
my $url = 'http://www.gmail.com/';
my $response = $m->get($url);
if (!$response->is_success) {
die "Login page unreachable $url: ", $response->status_line, "\n";
}
$m->submit_form(
form_number => 1,
fields => {
'Username' => $Email,
'Password' => $Password,
},
);
$response = $m->submit();
$m->add_header(
"Connection" => "keep-alive",
"Keep-Alive" => "115");
#$response = $m->click();
if ($response->is_success) {
print "Login Successful!\n";
} else {
die "Login failed: ", $response->status_line, "\n";
}
my $ShellExecute =
new Win32::API( "shell32", "ShellExecute", [qw(N P P P P N)], 'N' );
my $GetDesktopWindow =
new Win32::API( "user32", "GetDesktopWindow", [], 'N' );
my $hWnd = $GetDesktopWindow->Call();
$ShellExecute->Call( $hWnd, 'open', $url, '', '', 1 );