[英]Perl WWW:Mechanize Form fill does not work
我在用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: </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ü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();
可能有一種方法可以存儲Cookie ???
WWW::Mechanize
將自動為您處理所有cookie。 因此,在此類構造中不需要:
cookie_jar => HTTP::Cookies->new( file => "./cookies.txt" )
當然, 如果您不想稍后將這些Cookie加載到另一個腳本(或同一腳本的另一個運行)中,則 ...
我主要看到的是Javascript的md5pass()
函數(我相信)會在您的表單中設置hash
字段。 因此,您只需要在代碼中模擬此函數並提交以下值即可:
$mech->submit_form(
with_fields => {
user => $user,
passwd => $password,
hash => $hash,
},
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.