Perl WWW :: Mechanize方法在AIX中不起作用 [英] Perl WWW::Mechanize methods not working in AIX

查看:105
本文介绍了Perl WWW :: Mechanize方法在AIX中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的要求,即屏幕抓取网页(基于简单URL的报告)并将HTML响应定向到输出文件。但是,该网址将重定向到带有基于表单的身份验证(无JavaScript)的身份验证(HTTPS登录)页面,并且在身份验证后,我尝试查看的报告应显示在 $ response (作为HTML)。有趣的是,我的代码在Windows机器上可以正常工作,但是下面的相同代码在AIX机器上却不能正常工作,并且 click_button()函数调用似乎没有任何作用。我已经尝试过 click() submit(),但是都没有用,所以我没有得到所有的实际报告get是HTML输出文件中的登录屏幕。任何想法,有什么问题吗?

I have a simple requirement of screen scraping a web-page (simple URL based reports) and direct the HTML response to an output file. The URL will however redirect to an authentication (HTTPS Login) page with "form based" authentication (no javascript) and upon authentication the report I am trying to view should show up in the $response (as HTML). Interestingly, my code is working just fine in a Windows machine, however the same code below is not working in AIX machine and it looks like the click_button() function call does nothing. I have tried click(), submit(), but none is working so instead of getting the actual report all I get is the logon screen in the HTML output file. Any ideas, what can be wrong?

use WWW::Mechanize;
use strict;

my $username = "admin";
my $password = "welcome1";  
my $outpath  = "/home/data/output";
my $fromday = 7;
my $url  = "https://www.myreports.com/tax_report.php";
my $name = "tax_report";
my $outfile = "$outpath/$name.html";

my $mech = WWW::Mechanize->new(noproxy =>'0');  

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900; 
$mon++;     # since it will start from 0
$mday--;    # yesterdays date (to day)
$fromday = $mday - $days; #(from day)

#Create URL extension for generating report with previous date
my $dt_range = "?Y&dc_date1=$mon%2F$fromday%2F$year&dc_date2=$mon%2F$mday%2F$year"; 
my $url  = $url . $dt_range;

$mech->get($url);
$mech->field(login => "$username");
$mech->field(passwd => "$password");

$mech->add_handler("request_send",  sub { shift->dump; return });
$mech->add_handler("response_done", sub { shift->dump; return });

$mech->click_button(value=>"Login now");

my $response = $mech->content();

print "Generating report: $name...\n";

open (OUT, ">>$outfile")|| die "Cannot create report file $outfile";
print OUT "$response";
close OUT;

两台机器上的WWW :: Mechanize版本相同,即1.54,但Win机器perl版本是5.10.1,而AIX机器的Perl版本是5.8.8。

The WWW::Mechanize version in both the Machines are same i.e. 1.54 but the Win machine perl version is 5.10.1 whereas the AIX machine's Perl version is 5.8.8.

使用的其他替代方法-

my $inputobject=$mech->current_form()->find_input( undef,'submit' );
print $inputobject->value . "\n";
$mech->click_button(input => $inputobject);
print $mech->status() . "\n";

$ inputobject显示正确的按钮元素,如HTML源代码中一样,第二个打印返回状态为200,显然代表OK。但是它仍然不能在AIX机器上工作。

The $inputobject shows the correct button element as in the HTML source and the second print returns a status of 200 which apparently stands for OK. But its still not working in the AIX machine.

更新-似乎我尝试连接的站点具有不受信任的位置SSL证书。我在Windows PC,Mac和AIX的三台不同机器上尝试了该程序。在Windows机器上,该程序可以运行,并且我能够通过浏览器(Chrome,Firefox,IE)登录到该网站。但是,在Mac中,登录名(通过浏览器)将无法使用,并且显示不可信的证书错误(或警告!),这可能意味着未设置代理设置,Perl程序也无法使用。最后是Perl不能正常工作的AIX。不知道如何在此处绕过此不受信任的SSL证书问题。

UPDATE- It seems that the site I am trying to connect to has an un-trusted SSL certificate. I tried the program on three different machines Windows PC, Mac and AIX. On the Windows Machine the program works and I was able to login to the website through the browsers (Chrome, Firefox,IE). However in Mac, the login just won't work (through the browsers) and it shows an un-trusted certificate error (or warning!) this probably means the proxy settings are not set up, the Perl program won't work either. And lastly the AIX where the Perl is not working as well. Not sure how to bypass this un-trusted SSL certificate issue here. Any help will be appreciated.

UPDATE2::脚本中包含以下代码行以查看日志记录详细信息,并发现我正在重新定向(HTTP 302),因为我的IP被服务器防火墙过滤了。一旦将AIX ip添加到服务器的防火墙例外中,该脚本便可以正常工作。下面的两行是救生员-

UPDATE2: Included below lines of code in the script to see logging details and found that I was being re-directed (HTTP 302) since my IP was filtered by the server Firewall. Once the AIX ip was added to the server's firewall exception the script worked perfectly. The two lines below were the life saver-

$mech->add_handler("request_send",  sub { shift->dump; return });
$mech->add_handler("response_done", sub { shift->dump; return });


推荐答案

能否在<$ c $之前使用以下行c>我的$ mech = WWW :: Mechanize-> new(noproxy =>'0'); 您的perl代码,然后重试?

Can you use the following line before my $mech = WWW::Mechanize->new(noproxy =>'0'); of your perl code and try again ?

$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0;

这篇关于Perl WWW :: Mechanize方法在AIX中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆