使用Perl的WWW :: Mechanize填写加密的登录/密码字段ID

时间:2014-05-06 02:01:50

标签: perl field www-mechanize encryption

我想使用WWW :: Mechanize查看我的帐户余额(网上银行)和Perl脚本。该站点为Sparkasse Duerenen (online banking)但是,字段ID似乎具有特殊的加密机制。在每个新页面加载时,将使用新的唯一名称生成ID。

如果您查看HTML源代码,您将在字段" Legimtation ID"位于左侧,您可以输入登录数据。

  <input id="TgQZqInrKGXTjHOP" class="loginfeld" type="text" onkeyup="testEmptyInput(event,this);" onblur="testEmptyInput(event,this);" onfocus="testEmptyInput(event,this);" value="" maxlength="16" size="10" name="TgQZqInrKGXTjHOP"></input>

PIN /密码也一样。

输入ID似乎每次都有唯一生成的名称。我无法使用WWW :: Mechanize的静态预定义字段名称填充此字段。你们现在会提出什么建议?如何填写此字段以提交POST请求。

1 个答案:

答案 0 :(得分:0)

我建议使用Mojo::DOM来解析返回的HTML并查找包含class="loginfeld"type="text"的输入。然后只需提取属性name

关于使用Mojo::DOM的短暂8分钟视频,请查看Mojocast Episode 5

以下内容将登录字段名称打印到STDOUT。您只需将WWW::Mechanize的返回html提供给Mojo::DOM,而不是使用此Mojo::UserAgent

的方法
#!/usr/bin/perl 

use strict;
use warnings;

use Mojo::UserAgent;

my $url = 'https://bankingportal.sparkasse-dueren.de/portal/portal/Starten';

my $ua = Mojo::UserAgent->new;
my $dom = $ua->get($url)->res->dom;

# Print Login field names
for my $input ($dom->find('input')->each) {
    if ($input->attr('class') eq 'loginfeld') {
        if ($input->attr('type') eq 'text') {
            print "Login field name = " . $input->attr('name') . "\n";
        }
        if ($input->attr('type') eq 'password') {
            print "Password field name = " . $input->attr('name') . "\n";
        }
    }
}
相关问题