我想使用WWW :: Mechanize從網站搜索內容,但要能夠做到這一點,我必須先使用我的註冊用戶名和密碼登錄,但我不能用這個碼。必須改變什麼才能成功提交表單。謝謝。Perl WWW ::機械化證書
use strict;
use warnings;
use WWW::Mechanize;
my $username = "username";
my $password = "password";
my $cookie_jar;
my $url = "http://www.albumartexchange.com/forums/ucp.php?mode=login";
my $mech = WWW::Mechanize->new(cookie_jar => $cookie_jar);
$mech->credentials($username, $password);
$mech->get($url);
$mech->success() or die "Failed";
$mech->submit_form(
form_number => 4,
);
die "Submit failed" unless $mech->success;
$mech->save_content('log.txt');
UPDATE:
use strict;
use warnings;
use WWW::Mechanize;
my $cookie_jar;
my $mech = WWW::Mechanize->new(cookie_jar => $cookie_jar);
$mech->get('http://www.albumartexchange.com/forums/ucp.php?mode=login');
$mech->submit_form(
form_number => 4,
fields => {
'username'
=> 'some_username',
'password'
=> 'some_password',
}
);
$mech->save_content('log.txt');
順便說一句,爲什麼你使用$ cookie_jar? Cookie中的內容默認在Mechanize中啓用,所以我相信你不需要在這裏使用它。 – gangabass