2013-04-12 2 views
1

WWW :: Mechanize로 로그인 폼을 작성하는 데 좋은 문제가 있습니다.Perl WWW : Mechanize 폼 채우기가 작동하지 않습니다.

<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 형태가 있지만, 필드 :

첫째, 나는 당신에게 unfotunatelly 독일어에있는 웹 사이트의 일부를 표시합니다 username은 "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 :: 기계화 :: 셸 다시 시도 결국 펄 스크립트를 구축 한

... 내가 로그인 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(); 

쿠키를 저장할 수있는 방법이 있습니까?

답변

0

WWW::Mechanize은 자동으로 모든 쿠키를 처리합니다. 그래서 같은 구조의 필요가 없습니다 :

물론 나중에 다른 스크립트 (또는 같은 스크립트의 다른 실행)에 이러한 쿠키를로드하지 않으려는 경우의
cookie_jar => HTTP::Cookies->new(file => "./cookies.txt") 

...

내가 볼 수있는 가장 중요한 것은 Javascript의 md5pass() 기능이며 (나는) hash 필드를 양식에 설정합니다. 따라서 코드에서이 함수를 에뮬레이션하고이 값을 제출해야합니다.

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

많은 감사의 말 ...하지만 어떻게하면 $ hash 변수를 생성 할 수 있습니까? 그것은 "username"& password "또는"password "이상의 md5입니까? 감사합니다 – user2274418

+0

감사합니다. 작동합니다 !! 당신은 오늘의 나의 영웅입니다 ... – user2274418

+0

$ hash = md5_hex ($ FLPASSWORD); 않습니다 이 모든 후 ...이 스크립트 modificatin 매력처럼 작동합니다. 많은, 많은 감사합니다! – user2274418