简体   繁体   English

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

[英]WWW::Mechanize to access secure website

I have a script I am trying to log into an Oracle EBS page with and I believe I am one line away, (I could be wrong) from doing this. 我有一个脚本要尝试登录到Oracle EBS页面,并且我认为这样做与我相距仅一步之遥(我可能错了)。 Below is my script and attached is the section of from data I think the answer is there some where. 以下是我的脚本,并随附了我认为答案在哪里的数据部分。

I think its the submit and submit form line where I think I am failing. 我认为它的提交和提交表格行失败了。 But if anyone sees other discrepancies, please let me know. 但是,如果有人看到其他差异,请告诉我。 I do see where the username in the script is in the form but not the password. 我确实看到了脚本中用户名的形式,但没有密码。 I do believe the script has the right entry, but correct me if I am wrong. 我确实相信脚本的输入正确,但是如果我写错了,请纠正我。

Thanks in advance! 提前致谢!

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); 

Form snipet: 表格摘要:

"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 does not handle JavaScript. WWW :: Mechanize不处理JavaScript。 If JavaScript is involved (and it seems so, onclick="submitForm... ), use some other module (eg WWW::Mechanize::Firefox ). 如果涉及JavaScript(似乎是onclick="submitForm... ),请使用其他模块(例如WWW :: Mechanize :: Firefox )。

You don't need this lines ( WWW::Mechanize will work with cookies for you automatically): 您不需要以下行( WWW::Mechanize将自动为您使用Cookie):

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

Next... Are you sure your link have this text : submitForm ? 下一步...您确定您的链接包含以下文本submitForm吗? May be you need: 可能您需要:

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

I recommend to try this code instead (for submit part): 我建议改为尝试以下代码(对于提交部分):

$mech->submit_form(

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

Update: Another way: you need to use tool like Firefox's HTTPFox add-on and find what data is send to the target site after each request. 更新:另一种方法:您需要使用Firefox的HTTPFox插件之类的工具,并在每次请求后查找将哪些数据发送到目标站点。 Next you simply send same data with $mech . 接下来,您只需使用$mech发送相同的数据。

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

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