Perl WWW:机械化表格填充不起作用

问题描述:

我用WWW :: Mechanize填写登录表单有一些不错的问题。Perl WWW:机械化表格填充不起作用

首先,我会告诉你的网站,这是unfotunatelly德国的一部分:

<form action="/login.php" method="post" onsubmit="md5pass();"> 
<p><br/></p> 
<table width="350" border="0" cellpadding="5" cellspacing="0" align="center" style="border:dotted 1px black"> 
    <tr bgcolor="#ffb442" align="center"> 
     <td colspan="2"> 
      <p></p><b>Bitte <a href="http://www.xyz.de/startseite.php">Flirtlife</a> Usernamen und Passwort eingeben!</b></p> 
     </td> 
    </tr> 
    <tr bgcolor="#ffae35"> 
     <td> 
      <b>Username: &nbsp;</b></font> 
     </td> 
     <td> 
      <input type="text" name="user" size="25" maxlength="40" value=""> 
      <input type="hidden" name="relocate" value="/profil.php?user=1180038">   </td> 
    </tr> 
    <tr bgcolor="#ffae35"> 
     <td> 
      <b>Passwort: </b> 
     </td><td> 
      <input type="password" id="passwd" name="passwd" size="25" maxlength="32"> 
     </td> 
    </tr> 
    <tr bgcolor="#ffae35"> 
     <td> 
      <b>Autologin: </b> 
     </td><td> 
      <input onclick="toggle('hinweis_setautologin', 'setautologin');" type="checkbox" id="setautologin" name="setautologin" value="true"> automatisch einloggen 
     </td> 
    </tr> 
    <tr> 
     <td align="center" colspan="2" id="hinweis_setautologin" style="background:#fff;font-size:9px;display:none;" bgcolor="#ffae35"> 
      Du wirst solange automatisch eingeloggt bis du auf LOGOUT klickst oder auf einem anderen Rechner das AUTOLOGIN aktivierst. 
     </td> 
    </tr> 
    <tr bgcolor="#ffae35"> 
     <td> 
      <b>Unsichtbar:</b> 
     </td><td> 
      <input onclick="toggle('hinweis_invisible', 'invisible');" type="checkbox" id="invisible" name="invisible"> unsichtbar einloggen <img src="images/prem_small.gif" alt="prem_small" height="12"/> 
     </td> 
    </tr> 
    <tr> 
     <td align="center" colspan="2" id="hinweis_invisible" style="background:#fff;font-size:9px;display:none;" bgcolor="#ffae35"> 
      Wenn du Premium-User bist, dann loggst du dich dieses mal unsichtbar ein. Du erscheinst dann als OFFLINE und man sieht dich nicht auf den Profilbesuchern. 
     </td> 
    </tr> 
    <tr bgcolor="#ffb442"> 
     <td colspan="2" align="center"> 
      <p></p><a href="sendpassword.php"><strong>Passwort vergessen?</strong></a></p> 
      <p></p><input type="hidden" id="hash" name="hash" value=""><input id="loginsubmit" type="submit" value="Absenden"></p> 
     </td> 
    </tr> 
</table> 
<p align="center"> 
    <b>Hinweis:</b> Cookies und Javascript m&uuml;ssen aktiviert sein!<br/> 
    <a href="http://hilfe.xyz.de/faq/doku.php/das_login_funktioniert_nicht"><b>Probleme beim Login?</b></a> 
</p> 
<p align="center"><a href="/registrieren.php"><img src="/images/teaser.gif"></a></p> 
</form> 

嗯......你可以看到,只有1表格填写,但领域用户名没有“ID”。

其次,有一个按钮来确认登录数据。

我已经试过这样:

my $a = WWW::Mechanize->new( 
    cookie_jar => HTTP::Cookies->new(file => "./cookies.txt") 
    ); 

$a->get("$FLUserProfileLoginURL$FLuserID"); 
unless($a->success()) { 
    print "Problem while loading site...\n\n"; 
     exit; 
    } 
$dest = $a->response->content; 

@FORMS = $a->forms; 

for $entry (@FORMS) { 
    print Dumper ($entry); 
} 

它显示:

$VAR1 = bless({ 
      'default_charset' => 'UTF-8', 
      'enctype' => 'application/x-www-form-urlencoded', 
      'accept_charset' => 'UNKNOWN', 
      'action' => bless(do{\(my $o = 'http://www.xyz.de/login.php')}, 'URI::http'), 
      'method' => 'POST', 
      'attr' => { 
         'onsubmit' => 'md5pass();', 
         'method' => 'post' 
         }, 
      'inputs' => [ 
          bless({ 
            'maxlength' => '40', 
            'value_name' => '', 
            'value' => '', 
            'name' => 'user', 
            'type' => 'text', 
            'size' => '25' 
            }, 'HTML::Form::TextInput'), 
          bless({ 
            'readonly' => 1, 
            'value_name' => '', 
            'value' => '/profil.php?user=1180038', 
            'name' => 'relocate', 
            'type' => 'hidden' 
            }, 'HTML::Form::TextInput'), 
          bless({ 
            'maxlength' => '32', 
            'value_name' => '', 
            'name' => 'passwd', 
            'id' => 'passwd', 
            'type' => 'password', 
            'size' => '25' 
            }, 'HTML::Form::TextInput'), 
          bless({ 
            'current' => 0, 
            'menu' => [ 
               { 
                'seen' => 1, 
                'value' => undef, 
                'name' => 'off' 
               }, 
               { 
                'value' => 'true', 
                'name' => 'automatisch einloggen' 
               } 
               ], 
            'name' => 'setautologin', 
            'onclick' => 'toggle(\'hinweis_setautologin\', \'setautologin\');', 
            'id' => 'setautologin', 
            'type' => 'checkbox' 
            }, 'HTML::Form::ListInput'), 
          bless({ 
            'current' => 0, 
            'menu' => [ 
               { 
                'seen' => 1, 
                'value' => undef, 
                'name' => 'off' 
               }, 
               { 
                'value' => 'on', 
                'name' => 'unsichtbar einloggen prem_small' 
               } 
               ], 
            'name' => 'invisible', 
            'onclick' => 'toggle(\'hinweis_invisible\', \'invisible\');', 
            'id' => 'invisible', 
            'type' => 'checkbox' 
            }, 'HTML::Form::ListInput'), 
          bless({ 
            'readonly' => 1, 
            'value_name' => '', 
            'value' => '', 
            'name' => 'hash', 
            'id' => 'hash', 
            'type' => 'hidden' 
            }, 'HTML::Form::TextInput'), 
          bless({ 
            'value_name' => '', 
            'value' => 'Absenden', 
            'id' => 'loginsubmit', 
            'type' => 'submit' 
            }, 'HTML::Form::SubmitInput') 
         ] 
      }, 'HTML::Form'); 

不幸,我不能发送正确的 “提交表单” 这个网站。 可能的问题是,有一个复选框来激活,这称为“setautologin”。

任何帮助将是伟大的。

UPDATE

我与WWW ::机械化::壳牌试图再次,构建一个Perl脚本,毕竟...... 首先我用“得到”来获取登录URL,然后“fillout”填写所有的数据。

不幸的是,它让我回到了login.php。

#!/usr/bin/perl -w 
use strict; 
use WWW::Mechanize; 
use WWW::Mechanize::FormFiller; 
use URI::URL; 

my $agent = WWW::Mechanize->new(autocheck => 1); 
my $formfiller = WWW::Mechanize::FormFiller->new(); 
$agent->env_proxy(); 

    $agent->get('http://www.xyz/login.php'); 
    $agent->form_number(1) if $agent->forms and scalar @{$agent->forms}; 
    $formfiller->add_filler('user' => Fixed => 'MyUsername'); 
    $formfiller->add_filler('passwd' => Fixed => 'MyPassword'); 
    $formfiller->add_filler('setautologin' => Fixed => 'true'); 
    $formfiller->add_filler('invisible' => Fixed => 'off');$formfiller->fill_form($agent->current_form); 
    $agent->submit(); 

有可能是存储cookie的方式???

WWW::Mechanize会自动处理所有的cookies。所以在这样的构造没有必要:

cookie_jar => HTTP::Cookies->new(file => "./cookies.txt") 
当然 如果你不想这些cookie加载后进入另一个脚本(或同一脚本的另一个运行)

...

我看到的主要是Javascript的md5pass()函数(我相信)将在您的表单中设置hash字段。所以,你只需要在你的代码,模仿此功能,并提交该值:到目前为止

$mech->submit_form(
    with_fields => { 
     user => $user, 
     passwd => $password, 
     hash => $hash, 
    }, 
); 
+0

非常感谢...但是...我怎么能生成$散列变量?它是在“用户名”和密码”或只是‘密码’一个MD5 ??? 问候 – user2274418

+0

伟大的!它的工作原理!!你是我的英雄的一天... – user2274418

+0

$哈希= md5_hex($ FLPASSWORD);不这一切......在此之后,你的脚本修改工作就像魅力。许多,非常感谢! – user2274418