登录网站并在网络浏览器中打开它

时间:2013-06-20 06:52:10

标签: windows perl

我是perl的新手,我从机械化开始。

我成功登录了一个网站,但之后我想打开网站 我的浏览器在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 );

1 个答案:

答案 0 :(得分:2)

哎呀。你不能这样做。 您是否曾使用Internet Explorer登录gmail,然后希望它能在Firefox中运行?

...

如果您需要使用浏览器登录you should probably just get perl to log in with your browser.

如果你真的需要只使用机械化,then you probably need mechanize to store the same cookies your browser uses.

相关问题