简体   繁体   English

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

[英]Login to a website and open it in web browser

I am new to perl and i have started with mechanize. 我是perl的新手,我从机械化开始。

I logged in to a website sucessfully but after that i wanted to open the website in my browser in windows it just opens the website instead of after logging in. 我成功登录了一个网站,但之后我想在我的浏览器中打开网站,它只是打开网站而不是登录后。

#!/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 );

Argh. 哎呀。 You can't just do that. 你不能这样做。 Do you ever log in to gmail using internet explorer, and then expect it to work in firefox? 你有没有使用Internet Explorer登录gmail,然后期望它在firefox中工作?

... ...

If you need to log in with your browser, you should probably just get perl to log in with your browser. 如果您需要使用浏览器登录,则应该只需使用perl即可使用浏览器登录。

If you really need to do it with just mechanize, then you probably need mechanize to store the same cookies your browser uses. 如果你真的需要只使用机械化, 那么你可能需要机械化来存储浏览器使用的相同的cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM