使用WWW :: Mechanize登录网页,无需登录,但使用perl进行javascript登录

时间:2012-09-10 14:30:07

标签: javascript forms perl www-mechanize

我使用perl的WWW::Mechanize来自动化来自许多Intranet登录表单的数据抓取。

现在,我发现一个网站不使用登录表单进行登录,但只使用表格中的javascript!

我不知道如何登录和抓取我感兴趣的数据。请帮助我在perl中进行编码以进行登录和数据抓取。

这是登录页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<title>WFM eCare</title>






<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>




<link rel="stylesheet" type="text/css" href="/WFMeCare/zkau/web/660e7a2d/eCareTheme/zul/css/normie.css.dsp;jsessionid=85C3D62E725D85FA9CE7C42C57B7C2C4.ecare2"/>
<link rel="stylesheet" type="text/css" href="/WFMeCare/zkau/web/660e7a2d/eCareTheme/wfm/css/wfmie.css.dsp;jsessionid=85C3D62E725D85FA9CE7C42C57B7C2C4.ecare2"/>
<link rel="stylesheet" type="text/css" href="/WFMeCare/zkau/web/660e7a2d/eCareTheme/zkex/zul/css/zkexie.css.dsp;jsessionid=85C3D62E725D85FA9CE7C42C57B7C2C4.ecare2"/>
<link rel="stylesheet" type="text/css" href="/WFMeCare/zkau/web/660e7a2d/eCareTheme/zkmax/zul/css/zkmaxie.css.dsp;jsessionid=85C3D62E725D85FA9CE7C42C57B7C2C4.ecare2"/>
<link rel="stylesheet" type="text/css" href="/WFMeCare/css/ecare.css;jsessionid=85C3D62E725D85FA9CE7C42C57B7C2C4.ecare2"/>


<script type="text/javascript" src="/WFMeCare/zkau/web/660e7a2d/js/zk/zk.js.dsp;jsessionid=85C3D62E725D85FA9CE7C42C57B7C2C4.ecare2" charset="UTF-8">
</script>
<script type="text/javascript" src="/WFMeCare/zkau/web/660e7a2d/js/zk/lang.js.dsp;jsessionid=85C3D62E725D85FA9CE7C42C57B7C2C4.ecare2" charset="UTF-8">
</script>
<script type="text/javascript" src="/WFMeCare/zkau/web/660e7a2d/js/wfm.js;jsessionid=85C3D62E725D85FA9CE7C42C57B7C2C4.ecare2" charset="UTF-8">
</script>
<script type="text/javascript" src="/WFMeCare/zkau/web/660e7a2d/js/clipboard.js;jsessionid=85C3D62E725D85FA9CE7C42C57B7C2C4.ecare2" charset="UTF-8">
</script>
<script type="text/javascript">
zk_ver='3.6.4';
zk.build='10031815';
zk_procto=900;
zk_tipto=800;
zk_resndto=9000;
zk_clkflto=0;
zk.debugJS=true;
zk.eru={};zk.erusp={};

</script>



<link rel="shortcut icon" type="image/x-icon" href="/WFMeCare/images/favicon.jpg;jsessionid=85C3D62E725D85FA9CE7C42C57B7C2C4.ecare2"/>
<script type="text/javascript" src="/WFMeCare/js/SynchroListbox.js;jsessionid=85C3D62E725D85FA9CE7C42C57B7C2C4.ecare2" charset="UTF-8">
</script>


</head>
<body>

<div class="zk" id="z_bk_0" z.dtid="gbkl1" style="width:100%;height:100%;" z.zidsp="page" z.au="/WFMeCare/zkau;jsessionid=85C3D62E725D85FA9CE7C42C57B7C2C4.ecare2">
<div id="z_bk_1">










<div class="zk" id="z_bk_2" z.dtid="gbkl1" style="width:100%;height:100%;" z.zidsp="page">




<div id="z_bk_3" z.type="zul.wnd2.Wnd2" z.autoz="true" class="z-window-overlapped" style="position:absolute;visibility:hidden;width:420px;" z.zcls="z-window-overlapped" z.float="true" z.onOK="true" z.onCancel="true" z.pos="center" z.mode="overlapped" z.visible="true" z.minheight="100" z.minwidth="200" z.conshow="anima.appear( $e('z_bk_3'));" z.conhide="anima.fade( $e('z_bk_3'),500)"><div class="z-window-overlapped-tl"><div class="z-window-overlapped-tr"></div></div><div class="z-window-overlapped-hl"><div class="z-window-overlapped-hr"><div class="z-window-overlapped-hm"><div id="z_bk_3!caption" class="z-window-overlapped-header">

    <table id="z_bk_5" z.type="zul.widget.Capt" class="z-caption" z.zcls="z-caption" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr valign="middle">
<td align="left" class="z-caption-l">Accesso a WFM eCare! REL:12.7</td>
<td align="right" class="z-caption-r" id="z_bk_5!cave"></td>
</tr></table></div></div></div></div><div class="z-window-overlapped-cl"><div class="z-window-overlapped-cr"><div class="z-window-overlapped-cm"><div id="z_bk_3!cave" class=" z-window-overlapped-cnt">
    <span id="z_bk_4" z.type="zul.timer.Timer" style="display:none;" z.delay="500" z.repeats="false" z.running="false"></span>
    <table id="z_bk_6" z.type="zul.box.Box" class="z-vbox" z.zcls="z-vbox" z.vert="true" cellpadding="0" cellspacing="0">
<tr id="z_bk_7!chdextr" z.coexist="true" valign="top">
<td align="center"><img id="z_bk_7" z.type="zul.widget.Img" align="center" src="/WFMeCare/images/logoEcare4login.png;jsessionid=85C3D62E725D85FA9CE7C42C57B7C2C4.ecare2"/></td></tr>
<tr id="z_bk_7!chdextr2" class="z-vbox-sep"><td><img style="width:0;height:0"/></td></tr>
<tr id="z_bk_8!chdextr" z.coexist="true" valign="top">
<td align="center"><div id="z_bk_8" class="z-separator-hor" z.zcls="z-separator-hor">&nbsp;</div></td></tr>
<tr id="z_bk_8!chdextr2" class="z-vbox-sep"><td><img style="width:0;height:0"/></td></tr>
<tr id="z_bk_9!chdextr" z.coexist="true" valign="top">
<td align="center"><div id="z_bk_9" z.type="zul.grid.Grid" class="z-grid" style="width:80%;padding: 3,3,3,3; spacing: 3,3,3,3;" z.zcls="z-grid" z.scOddRow="z-grid-odd" z.fixed="false"><div id="z_bk_9!head" class="z-grid-header"><table width="100%" border="0" cellpadding="0" cellspacing="0" style="table-layout:fixed"><tbody style="visibility:hidden;height:0px"><tr id="z_bk_a!hdfaker" class="z-grid-faker"><th id="z_bk_b!hdfaker" class="z-column " style="width:25%;" z.zcls="z-column"><div style="overflow:hidden"></div></th></tr></tbody><tr id="z_bk_a" z.type="Cols" class="z-columns" z.zcls="z-columns" z.rid="z_bk_9" z.columnsgroup="true" z.columnshide="true" z.mpop="zk_n_a"align="left"><th id="z_bk_b" z.type="Col" class="z-column " style="width:25%;" z.zcls="z-column"><div id="z_bk_b!cave" class="z-column-cnt"></div></th>
</tr>
</table></div><div id="z_bk_9!body" class="z-grid-body"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tbody style="visibility:hidden;height:0px"><tr id="z_bk_a!bdfaker" class="z-grid-faker"><th id="z_bk_b!bdfaker" class="z-column " style="width:25%;" z.zcls="z-column"><div style="overflow:hidden"></div></th></tr></tbody><tbody id="z_bk_c" class="z-rows" z.zcls="z-rows">
<tr z.type="Grw" id="z_bk_d" class="z-row " z.zcls="z-row" z.rid="z_bk_9" z.visible="true"><td z.type="Gcl" id="z_bk_e!chdextr" class="z-row-inner"><div id="z_bk_e!cell" class="z-row-cnt"><span id="z_bk_e" class="z-label" style="font-weight: bolder;" z.zcls="z-label" class="z-label">Login</span></div></td>
<td z.type="Gcl" id="z_bk_f!chdextr" class="z-row-inner"><div id="z_bk_f!cell" class="z-row-cnt"><input id="z_bk_f" z.type="zul.vd.Txbox" class="z-textbox" style="width:98%;font-style: italic; font-weight: bolder;" z.zcls="z-textbox" z.onOK="true" z.ermg="Inserisci un utente valido" z.srvald="both" type="text"/></div></td>
</tr>
<tr z.type="Grw" id="z_bk_g" class="z-row z-grid-odd" z.zcls="z-row" z.rid="z_bk_9" z.visible="true"><td z.type="Gcl" id="z_bk_h!chdextr" class="z-row-inner"><div id="z_bk_h!cell" class="z-row-cnt"><span id="z_bk_h" class="z-label" style="font-weight: bolder;" z.zcls="z-label" class="z-label">Password</span></div></td>
<td z.type="Gcl" id="z_bk_i!chdextr" class="z-row-inner"><div id="z_bk_i!cell" class="z-row-cnt"><input id="z_bk_i" z.type="zul.vd.Txbox" class="z-textbox" style="width:98%;font-style: italic; font-weight: bolder;" z.zcls="z-textbox" z.onOK="true" z.ermg="Inserisci una password valida" z.srvald="both" type="password"/></div></td>
</tr>
</tbody>

</table></div></div></td></tr>
<tr id="z_bk_9!chdextr2" class="z-vbox-sep"><td><img style="width:0;height:0"/></td></tr>
<tr id="z_bk_j!chdextr" z.coexist="true" valign="top">
<td align="center"><div id="z_bk_j" align="center">
    <span z.type="zul.btn.Button" id="z_bk_k" class="z-button"   z.zcls="z-button"><table id="z_bk_k!box" cellspacing="0" cellpadding="0" border="0" class="z-button " style="font-weight: bolder;">
<tr><td class="z-button-tl"></td><td class="z-button-tm"></td><td class="z-button-tr"></td></tr>
<tr><td class="z-button-cl"><button id="z_bk_k!real" class="z-button"></button></td><td class="z-button-cm"><img src="/WFMeCare/images/btnLogin.png;jsessionid=85C3D62E725D85FA9CE7C42C57B7C2C4.ecare2" align="absmiddle" id="z_bk_k!hvig"/> Accedi</td>
<td class="z-button-cr"><div></div></td></tr>
<tr><td class="z-button-bl"></td><td class="z-button-bm"></td><td class="z-button-br"></td></tr>
</table></span></div></td></tr>
<tr id="z_bk_j!chdextr2" class="z-vbox-sep"><td><img style="width:0;height:0"/></td></tr>
<tr id="z_bk_l!chdextr" z.coexist="true" valign="top">
<td align="center"><img id="z_bk_l" z.type="zul.widget.Img" align="center" src="/WFMeCare/images/logoApplicationWFM.png;jsessionid=85C3D62E725D85FA9CE7C42C57B7C2C4.ecare2"/></td></tr>
<tr id="z_bk_l!chdextr2" class="z-vbox-sep"><td><img style="width:0;height:0"/></td></tr>
<tr id="z_bk_m!chdextr" z.coexist="true" valign="top">
<td align="center"><img id="z_bk_m" z.type="zul.widget.Img" align="center" src="/WFMeCare/images/logoApplicationTelecom.png;jsessionid=85C3D62E725D85FA9CE7C42C57B7C2C4.ecare2"/></td></tr>
<tr id="z_bk_m!chdextr2" class="z-vbox-sep"><td><img style="width:0;height:0"/></td></tr>
<tr id="z_bk_n!chdextr" z.coexist="true" valign="top">
<td align="center"><div id="z_bk_n" style="margin-right: 10px;" align="right">
        <span id="z_bk_o" class="z-label" style="width:100%;" z.zcls="z-label" class="z-label">Build :1503907 del 2012-08-20 16:00</span></div></td></tr>
</table></div></div></div></div><div class="z-window-overlapped-bl"><div class="z-window-overlapped-br"></div></div></div>
</div>

<noscript><div class="noscript"><p>Sorry, JavaScript must be enabled.<br/>Change your browser options, then <a href="">try again</a>.</p></div></noscript>


<script type="text/javascript">
zk.addInit(function(){
zk.process('clientInfo',"gbkl1");
zk.process('focus',"z_bk_f");
});
</script>


</div>
</div>





</body>
</html>

1 个答案:

答案 0 :(得分:1)

最后,JavaScript将调用另一个网页来启动会话。您必须弄清楚JavaScript的作用,最终调用的URL以及它传递的数据。这对你来说是更多的手工工作,但这就是它的完成方式。


编辑:我只想补充一点,我在之前的工作中使用这个混合html / js场景实现了一个刮刀。密钥ID尽可能自动化,并始终始终监控,因为他们可以随时更新页面,这通常会破坏您的刮刀。