Skip to content

Commit

Permalink
Use regex instead of unreliable HTML::Strip technique
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert authored and Steven N. Severinghaus committed Jul 1, 2010
1 parent 16e5ba9 commit 3345dff
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions Finance/Bank/US/INGDirect.pm
Expand Up @@ -5,7 +5,6 @@ use strict;
use Carp 'croak';
use LWP::UserAgent;
use HTTP::Cookies;
use HTML::Strip;
use Date::Parse;
use Data::Dumper;

Expand All @@ -17,11 +16,11 @@ Finance::Bank::US::INGDirect - Check balances and transactions for US INGDirect
=head1 VERSION
Version 0.05
Version 0.06
=cut

our $VERSION = '0.05';
our $VERSION = '0.06_01';

=head1 SYNOPSIS
Expand Down Expand Up @@ -143,17 +142,22 @@ Retrieve a list of accounts:
sub accounts {
my ($self) = @_;

my $hs = HTML::Strip->new;
my @lines = grep /command=goToAccount/, split(/[\n\r]/, $self->{_account_screen});
@lines = map { tr/\xa0/ /; $_ } split(/\n/, $hs->parse(join "\n", @lines));
# sometimes it is ok to use regular expressions to parse HTML
my @results = ();
while($self->{_account_screen}
=~ m{<a[^>]+class="[^"]*tabletext[^"]*"[^>]*>(.+?)</a>}gis) {
my $d = $1;
$d =~ s/\s{2,}//g;
push @results, $d;
}

my %accounts;
for (@lines) {
my @data = splice(@lines, 0, 3);
while (@results) {
my %account;
($account{type} = $data[0]) =~ s/^\s*(.*?)\s*$/$1/;
($account{nickname}, $account{number}, $account{balance}) = split /\s/, $data[1];
($account{available} = $data[2]) =~ s/^\s*(.*?)\s*$/$1/;
($account{type},
$account{nickname},
$account{balance},
$account{available}) = splice(@results, 0, 5);
$accounts{$account{number}} = \%account;
}

Expand Down

0 comments on commit 3345dff

Please sign in to comment.