1

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 つだけですが、ユーザー名のフィールドには「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」を呼び出す有効にするチェックボックスがあることです。

どんな助けでも素晴らしいでしょう。

アップデート

WWW::Mechanize::Shell でもう一度試してみましたが、結局 perl スクリプトを作成しました... 最初に "get" を使用してログイン 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();

おそらくクッキーを保存する方法があります???

4

1 に答える 1