perl WWW::Mechanize,链接重定向问题
我使用 WWW::Mechanize::Shell 来测试东西。
我的代码是这样的:
#!/usr/bin/perl
use WWW::Mechanize;
use HTTP::Cookies;
my $url = "http://mysite/app/login.jsp";
my $username = "username";
my $password = "asdfasdf";
my $mech = WWW::Mechanize->new();
$mech->cookie_jar(HTTP::Cookies->new());
$mech->get($url);
$mech->form_number(1);
$mech->field(j_username => $username);
$mech->field(j_password => $password);
$mech->click();
$mech->follow_link(text => "LINK A", n => 1);
$mech->follow_link(text => "LINK B", n => 1);
........................ ........................ ........................ 等等,
问题是下一个:
重定向到 web_page_x.html
LINK B (web_page_b.html),如果我打印 $mech->content() 的内容,则
,显示 web_page_b.html但我需要显示 web_page_x .html,自动提交 HTML 表单 (web_page_x.html)
问题是:
如何获取 web_page_x.html ?
谢谢
I use WWW::Mechanize::Shell to test stuff.
my code is this:
#!/usr/bin/perl
use WWW::Mechanize;
use HTTP::Cookies;
my $url = "http://mysite/app/login.jsp";
my $username = "username";
my $password = "asdfasdf";
my $mech = WWW::Mechanize->new();
$mech->cookie_jar(HTTP::Cookies->new());
$mech->get($url);
$mech->form_number(1);
$mech->field(j_username => $username);
$mech->field(j_password => $password);
$mech->click();
$mech->follow_link(text => "LINK A", n => 1);
$mech->follow_link(text => "LINK B", n => 1);
........................
........................
........................
etc, etc.
the problem is the next:
LINK B (web_page_b.html), make a redirect to web_page_x.html
if I print the contents of $mech->content(), display web_page_b.html
but i need to display web_page_x.html,to automatically submit a HTML form (web_page_x.html)
The question is:
How I can get web_page_x.html ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不首先测试一下
web_page_b.html
上是否存在包含重定向的代码(我猜测它是标记?),然后一旦您确定浏览器会执行此操作,请直接转到下一页。
这看起来像:
顺便说一句,如果您正在使用
WWW::Mechanize
进行任何类型的测试,您确实应该查看 Test::WWW::Mechanize 和其他 Perl 测试模块!它们让生活变得更加轻松。Why don't you first test to see if the code containing the redirect (I'm guessing it's a
<META>
tag?) exists onweb_page_b.html
, then go directly to the next page once you're sure that that's what a browser would have done.This would look something like:
Incidentally, if you're doing any kind of testing with
WWW::Mechanize
, you should really check out Test::WWW::Mechanize and the other Perl testing modules! They make life a lot easier.如果它没有真正重定向,那么您最好将正则表达式与该
follow_link
方法一起使用,而不仅仅是纯文本。例如:
其他链接也一样。
In case it doesn't really redirect, then you better use regex with that
follow_link
method rather than just plain text.such as:
same for the other link.