[英]How to get content of a page after submitting form with WWW::Mechanize?
I have a web page which is consist of a log in form . 我有一个包含登录表单的网页。 When I submit the form with WWW::Mechanize module in perl , The content of my page changes because username / password is wrong . 当我在perl中使用WWW :: Mechanize模块提交表单时,由于用户名/密码错误,页面的内容发生了变化。 I want to catch the content of the page after submitting form . 我想在提交表单后捕获页面的内容。 I tried to use this : 我试图用这个:
$mech->content;
But that's not what I need. 但这不是我所需要的。
This is a piece of my code : 这是我的一部分代码:
$fields = {
'usr' => $username,
'passwd' => $password[0]
};
$url = "http://blahblah.com/login/index.aspx?id=1";
$mech = WWW::Mechanize->new();
$mech->get($url);
$mech->submit_form(
form_number=> 1,
fields => $fields,
button => 'button'
)
$mech->content;
Also see : How to receive content of a page after submitting a form in perl? 另请参阅: 在perl中提交表单后如何接收页面内容?
the following code works for me 以下代码对我有用
#!/usr/bin/env perl
use strict;
use warnings;
use feature qw/ say /;
use WWW::Mechanize;
my $username = '';
my $password = '';
my $fields = {
usr => $username,
passwd => $password,
};
my $url = "http://localhost:3000/login";
my $mech = WWW::Mechanize->new();
$mech->get($url);
$mech->submit_form(
form_number => 1,
fields => $fields,
button => 'button'
);
say $mech->content;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.