繁体   English   中英

WWW ::机械化访问安全网站

[英]WWW::Mechanize to access secure website

我有一个脚本要尝试登录到Oracle EBS页面,并且我认为这样做与我相距仅一步之遥(我可能错了)。 以下是我的脚本,并随附了我认为答案在哪里的数据部分。

我认为它的提交和提交表格行失败了。 但是,如果有人看到其他差异,请告诉我。 我确实看到了脚本中用户名的形式,但没有密码。 我确实相信脚本的输入正确,但是如果我写错了,请纠正我。

提前致谢!

use strict;
use warnings;
use WWW::Mechanize;
use HTTP::Cookies;
my $outfile = "test";
my $url = "http ://url_address:portnumber /OA_HTML/Login";
my $username = 'johndoe';
my $password = 'johndoe123';
my $mech = WWW::Mechanize->new();
$mech->cookie_jar(HTTP::Cookies->new());
$mech->get($url);
$mech->form_id('DefaultFormName');
$mech->field("usernameField", $username);
$mech->field("passwordField", $password);
$mech->submit_form(

form_id => "DefaultFormName",
fields => {
    usernameField => $username,
    passwordField => $password,
    '_FORM_SUBMIT_BUTTON' => "SubmitButtonofEPmL1A",
},
);
my $output_page = $mech->content();
print $output_page;
open(OUTFILE, ">$outfile");
binmode(OUTFILE, ":utf8");`enter code here`
print OUTFILE "$output_page";
close(OUTFILE); 

表格摘要:

"name="usernameField" size="0" type="text" value="johndoe">
< src="/OA_HTML/cabo/images/swan/t.gif" width="5"></td></tr><tr><td colspan="2"></td><td><span class="x2o">
(example: john.doe)</span></td></tr></table></td></tr><tr id="region41" align="left"><td id="region131" valign="top"><span class="x9g">*</span></td>
<td id="region51" valign="top"><span class="x9c">Password</span></td><td id="region61"><table id="passwordField__xc_" border="0" cellspacing="0" cellpadding="0"><tr><td align="right" nowrap></td><td></td>
<td valign="top" nowrap><input id="passwordField" title="Password" class=".LoginText" onchange="" name="passwordField" size="0" type="password">
< src="/OA_HTML/cabo/images/swan/t.gif" width="5"></td></tr><tr><td colspan="2"></td><td><span class="x2o">
(example: A1B2c3D4)</span></td></tr></table></td></tr><tr id="region132" align="left"><td id="region139">
</td><td id="region138"></td><td id="region133">
<button id="SubmitButton" title="Login" class="x7g" style="background-image:url(/OA_HTML/cabo/images/swan/btn-bg1.gif)" 
onclick="submitForm('DefaultFormName',1,{'_FORM_SUBMIT_BUTTON':'SubmitButtonofEPmL1A'});return false" type="submit">Login</button>< id="item11" src="/OA_HTML/cabo/images/swan/t.gif" width="2" height="1">"

WWW :: Mechanize不处理JavaScript。 如果涉及JavaScript(似乎是onclick="submitForm... ),请使用其他模块(例如WWW :: Mechanize :: Firefox )。

您不需要以下行( WWW::Mechanize将自动为您使用Cookie):

use HTTP::Cookies;
$mech->cookie_jar(HTTP::Cookies->new());

下一步...您确定您的链接包含以下文本submitForm吗? 可能您需要:

$mech->follow_link( url_regex => qr/submitForm/ );

我建议改为尝试以下代码(对于提交部分):

$mech->submit_form(

    form_id => "DefaultFormName",
    fields => {
        usernameField => $username,
        passwordField => $password,
        '_FORM_SUBMIT_BUTTON' => "SubmitButtonofEPmL1A",
    },
};

更新:另一种方法:您需要使用Firefox的HTTPFox插件之类的工具,并在每次请求后查找将哪些数据发送到目标站点。 接下来,您只需使用$mech发送相同的数据。

暂无
暂无

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

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