AppleScript C Perl Shell Xcode Other

How to write a login script to log to Online Banking?

Post Reply
coding / applescript     Views: 25934Prev .. Next
How to write a login script to log to Online Banking?Posted: Wednesday, June 16, 2010 [07:17:00] - 1
Posted by:MarkPosts: 2
My bank is PNC and I'd like to have balances checked daily.
Is there a way to write an applescript so balance is checked automatically?

There are too many form questions while logging to the bank site.
Any solutions?
It's a combined effort to write-up something like thatPosted: Wednesday, June 16, 2010 [16:56:43] - 2
rootPosted by:rootMember Since:
June 16 2010
Posts: 356
Hey Mark!
I did write something like that a while back. Please keep in-mind - there is no guarantee it will always work as Banks tend to change their layout, data structure and their design from time to time.
To run your program daily - you need a trigger. I use cron. The bad thing about cron for this job is that if bank's site was down at the time - there will be no results. Some sort of daemon would do a bit better job.

Since PNC login may ask security questions - we need a way to feed the right answers and keep information secure. I would not recommend keeping your Mac with that information in your office or on a laptop that might be lost or stolen.

It's a matter of personal preferences but I used AppleScript and Perl to do the job. The good thing about AppleScript here is it uses Safari to get the job done and PNC has no clue that balance was checked by the program.

Here it goes:
View Codetell application "System Events"
-- see if Safari is running
if not (exists process "Safari") then
set wCounter to 0
tell application "Safari"
activate
end tell
else
-- if Safari is not running - fire it up
set wCounter to 1
tell application "Safari"
activate
make new document
end tell
end if
delay 2
-- make sure is active in Safari
tell application process "Safari"
keystroke "," using {command down}
delay 2
get value of static text 1 of window 1
copy the result as string to varWindowName
click button "Security" of tool bar 1 of window varWindowName
delay 2
get value of checkbox "Enable Java" of group 1 of group 1 of window "Security"
copy the result as number to varResult
if varResult = 0 then
click checkbox "Enable Java" of group 1 of group 1 of window "Security"
end if
get value of checkbox "Enable " of group 1 of group 1 of window "Security"
copy the result as number to varOption
if varOption = 0 then
click checkbox "Enable " of group 1 of group 1 of window "Security"
end if
delay 2
click button 1 of window "Security"
end tell
delay 1
end tell

delay 3

-- go to PNC Bank website
tell application "Safari"
set URL of document 1 to "https://www.pnc.com/webapp/unsec/Homepage.do?siteArea=/PNC/Home/Personal"
set myURL to URL of document 1
delay 4
set web_page_is_loaded to false
set myCounter to 0
set maxCounter to 30
set my_delay to 1
-- wait for page to load
repeat until web_page_is_loaded is true
if name of window 1 contains "Loading" or name of window 1 contains "Untitled" or name of window 1 contains "w.htm" then
delay my_delay
else
set web_page_is_loaded to true
end if
set myCounter to myCounter + 1
if myCounter is maxCounter then
set web_page_is_loaded to true
end if
end repeat
delay 2
set Wname to get name of window 1
delay 1

if Wname does not contain "Personal Banking" then
tell application "System Events"
tell application "Safari"
keystroke return
end tell
end tell
end if

tell application "System Events"
tell application process "Safari"
-- replace "YOUR_BANK_LOGIN" with your actual login information
keystroke "YOUR_BANK_LOGIN"
delay 1
keystroke return
delay 3
set web_page_is_loaded to false
set myCounter to 0
set maxCounter to 30
set my_delay to 1
-- wait for page to load
repeat until web_page_is_loaded is true
if name of window 1 contains "Loading" or name of window 1 contains "Personal Banking" then
delay my_delay
else
set web_page_is_loaded to true
end if
set myCounter to myCounter + 1
if myCounter is maxCounter then
set web_page_is_loaded to true
end if
end repeat
delay 2
-- here we need to see the page content and for that we need to move away from the form field with "tab"
keystroke tab
delay 1
keystroke "a" using {command down}
delay 2
keystroke "c" using {command down}
delay 2
set log_text to (the clipboard) as text
delay 2
-- getting back to the form field
keystroke tab using {shift down}
delay 1
-- here we enter correct answers to our security questions
-- make sure you copy them exactly from PNC Bank site
if log_text contains "following Security Question" then
-- all three questions have one keyword we going to match with Perl below and answer to the question
-- separated by a ":"
set log_text to log_text & ">>>Father:John|Grandmother:Barbara|City:Cityville"
-- now we're pulling the correct answer from the Perl script "a.pnc.question.cgi" by feeding it the question
set thisAnswer to do shell script ("echo " & quoted form of log_text & " | perl /a.pnc.question.cgi")
set log_text to ""
keystroke thisAnswer
delay 1
keystroke return
delay 4
set web_page_is_loaded to false
set myCounter to 0
set maxCounter to 30
set my_delay to 1
-- wait for page to load again
repeat until web_page_is_loaded is true
if name of window 1 contains "Loading" then
delay my_delay
else
set web_page_is_loaded to true
end if
set myCounter to myCounter + 1
if myCounter is maxCounter then
set web_page_is_loaded to true
end if
end repeat
delay 1
end if
-- replace "LOGIN_PASSWORD" with your actual password
keystroke "LOGIN_PASSWORD"
delay 1
keystroke return
delay 3
set web_page_is_loaded to false
set myCounter to 0
set maxCounter to 30
set my_delay to 1
-- wait for page to load
repeat until web_page_is_loaded is true
if name of window 1 contains "Loading" or name of window 1 contains "Personal Banking" then
delay my_delay
else
set web_page_is_loaded to true
end if
set myCounter to myCounter + 1
if myCounter is maxCounter then
set web_page_is_loaded to true
end if
end repeat
delay 1
end tell
end tell
-- here we are looking for the link "Business Checking" on a loaded page
-- with
set FrameName to (do "window.frames[0].name" in document 1)
set LinkPresent to (do "top." & FrameName & ".document.links.length" in document 1)
set LinkPresent to LinkPresent - 1
set SaveData to ""
repeat with n from 0 to LinkPresent
set linkURL to (do "top." & FrameName & ".document.links[" & n & "].href" in document 1)
set linkName to (do "top." & FrameName & ".document.links[" & n & "].text" in document 1)
if linkName contains "Business Checking" then
-- now focus on a link
do "top." & FrameName & ".document.links[" & n & "].focus();" in document 1
set DoClick to 1
exit repeat
end if
end repeat
end tell

delay 1
tell application "System Events"
tell process "Safari"
-- now that we know we are on a right page - get an account balance
if DoClick > 0 then
keystroke "a" using {command down}
delay 2
keystroke "c" using {command down}
delay 2
set page_text to (the clipboard) as text
delay 2
-- reading Account Balance with Perl again
-- please adjust path to your Perl scripts as a full path (reference to home folder don't work)
do shell script ("echo " & quoted form of page_text & " | perl /a.get.bankbal.cgi")
set page_text to ""
delay 2
-- not go see account details
keystroke return

delay 5
set web_page_is_loaded to false
set myCounter to 0
set maxCounter to 30
set my_delay to 1
repeat until web_page_is_loaded is true
if name of window 1 contains "Loading" then
delay my_delay
else
set web_page_is_loaded to true
end if
set myCounter to myCounter + 1
if myCounter is maxCounter then
set web_page_is_loaded to true
end if
end repeat
delay 1

tell application "Safari"
set FrameName to (do "window.frames[0].name" in document 1)
set LinkPresent to (do "top." & FrameName & ".document.links.length" in document 1)
set LinkPresent to LinkPresent - 1
set SaveData to ""
repeat with n from 0 to LinkPresent
set linkURL to (do "top." & FrameName & ".document.links[" & n & "].href" in document 1)
set linkName to (do "top." & FrameName & ".document.links[" & n & "].text" in document 1)
if linkName contains "Security" then
do "top." & FrameName & ".document.links[" & n & "].focus();" in document 1
set DoClick1 to 1
exit repeat
end if
end repeat
end tell

if DoClick1 > 0 then
keystroke "a" using {command down}
delay 2
keystroke "c" using {command down}
delay 2
set page_text to (the clipboard) as text
delay 2
-- get and format transactions and details to view as an HTMl page (totally optional)
-- Perl script "a.get.bankbal.1.cgi" included below
do shell script ("echo " & quoted form of page_text & " | perl /a.get.bankbal.1.cgi")
set page_text to ""
delay 2
else
keystroke tab using {shift down}
delay 0.5
keystroke tab using {shift down}
delay 0.5
keystroke tab using {shift down}
delay 0.5
keystroke tab using {shift down}
delay 0.5
keystroke tab using {shift down}
delay 0.5
keystroke tab using {shift down}
delay 1
keystroke "a" using {command down}
delay 2
keystroke "c" using {command down}
delay 2
set page_text to (the clipboard) as text
delay 2
do shell script ("echo " & quoted form of page_text & " | perl /a.get.bankbal1.cgi")
set page_text to ""
delay 2
end if

else

keystroke tab using {shift down}
delay 0.5
keystroke tab using {shift down}
delay 0.5
keystroke tab using {shift down}
delay 0.5
keystroke tab using {shift down}
delay 0.5
keystroke tab using {shift down}
delay 0.5
keystroke tab using {shift down}
delay 1
keystroke "a" using {command down}
delay 2
keystroke "c" using {command down}
delay 2
set page_text to (the clipboard) as text
delay 2
do shell script ("echo " & quoted form of page_text & " | perl /a.get.bankbal.cgi")
set page_text to ""

end if

if wCounter < 1 then
keystroke "q" using {command down}
else
keystroke "w" using {command down}
end if

end tell
end tell

and this is a Perl script "a.pnc.question.cgi"
View Code#!/usr/bin/perl
unless($ENV{'SECURITYSESSIONID'}) {
$ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local:/usr/local/bin';
}
$vr = <STDIN>;
$spl = '>>>';$vr =~ s/\r//g;$vr =~ s/\n//g;
($vr,$hsh) = split(/$spl/,$vr);
@alh = split(/\|/,$hsh);
foreach $k (@alh) {($key,$val) = split(/\:/,$k);$recs{$key}=$val;}
$vr =~ s#(question\:\t)(.*?)(answer\:)##i;$qu = $2;
$qu =~ s/^\s+//;$qu =~ s/\s+$//;
if($qu =~ m/father/i && $qu =~ m/middle/i) {$qu='Father';}
elsif($qu =~ m/grandmother/i) {$qu='Grandmother';}
elsif($qu =~ m/city/i && $qu =~ m/born/i) {$qu='City';}
else{$qu='';}
if($recs{$qu}) {print "$recs{$qu}";}# else {print "none";}%recs=();exit(0);


Perl script "a.get.bankbal.cgi"

View Code#!/usr/bin/perl
unless($ENV{'SECURITYSESSIONID'}) {
$ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local:/usr/local/bin';
}
$vr = <STDIN>;
if(length($vr) > 10) {
open(TXT,">/Bank.Balance.raw.txt");print TXT $vr;close(TXT);
} ## END VR PRESENT
$vr='';

if(-f "/Bank.Balance.raw.txt") {
$d = `cat /Bank.Balance.raw.txt`;
if(-f "/Bank.Balance.raw.old.txt") {unlink "/Bank.Balance.raw.old.txt";}
`mv /Bank.Balance.raw.txt /Bank.Balance.raw.old.txt`;
$d =~ s/(\d)(\,)(\d{3})(\.)(\d{2})/$1$3$4$5/g;
$d =~ s#\$\d{1,4}\.\d{2}##;$amount = "$&";
$d =~ s#\$\d{1,4}\.\d{2}##;$availb = "$&";
if($amount) {open(TXT,">/Bank.Balance.curr.txt");print TXT "Balance: $amount\tAvailable: $availb";close(TXT);}$d='';
}


Perl script "a.get.bankbal.1.cgi"

View Code#!/usr/bin/perl
unless($ENV{'SECURITYSESSIONID'}) {
$ENV{'PATH'} = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local:/usr/local/bin';
}
$vr = <STDIN>;
if(length($vr) > 10) {
open(TXT,">/Bank.Balance.raw1.txt");print TXT $vr;close(TXT);
} ## END VR PRESENT
$vr='';

if(-f "/Bank.Balance.raw1.txt") {
$d = `cat /Bank.Balance.raw1.txt`;
$d =~ s/(\d)(\,)(\d{3})(\.)(\d{2})/$1$3$4$5/g;
if(-f "/Bank.Balance.raw1.old.txt") {unlink "/Bank.Balance.raw1.old.txt";}
`mv /Bank.Balance.raw1.txt /Bank.Balance.raw1.old.txt`;
while($d =~ /(\d{1,2}\/\d{1,2}\/\d{4})(.*?)(\$\d{1,6}\.\d{2})(\n|\r)/gs) {$collect{"$1\t$2"}=$3;$cmb="$1\t$2";push @ga, $cmb;}
($sh,$d) = split(/Account Summary/,$d);
($d,$sh) = split(/Additional/,$d);
$d =~ s/Account Alerts//;$d =~ s/^\s+//;$d =~ s/\s+$//;$d =~ s#(\:)(\$)#$1 $2#g;
$d =~ s#(\.\d{2})(\n|\r)(\d{2}\/)#$1 $3#g;
$d =~ s#(\:) #$1\t#g;$d =~ s#(\.\d{2}) (\d{2}\/)#$1\t$2#g;$d =~ s/\r/\n/g;$d =~ tr/\n\n//s;
$d =~ s#\t##g;$d =~ s#\n#\n#g;chomp $d;
$d =~ s#\n#\n#g;

$nowd=time;my $finaltime = localtime($nowd);$finaltime =~ tr/ //s;
open(TXT,">/Bank.Balance.curr1.txt");print TXT "PNC Bank Account Details on $finaltime:\n";
foreach $l (@ga) {$m = $collect{$l};
if($l =~ m/Description/i) {next;}
$l =~ s/\r//g;$l =~ s/\n//g;
$l =~ s#\t##g;
print TXT "$l$m\n";
} ## FOREACH END
print TXT "$d\n";
close(TXT);
$d='';

if($amount) {open(TXT,">/Bank.Balance.curr.txt");print TXT "Balance: $amount\tAvailable: $availb";close(TXT);}$d='';
}


I wrote this code a while back. It still works fine as of today but I can not write sensible comments on what it does and where at all points.
If using this code - variables need to be adjusted according to your PNC bank settings as far as security questions, login and password goes.

Save AppleScript as application with "Run only" and uncheck "Startup screen"
Keep the script copy in password protected "secret.sparseimage" image file so it minor changes come from PNC side - you can always do the changes to the script and re-save it as an app.There's no place like ~
RE: How to write a login script to log to Online Banking?Posted: Tuesday, June 28, 2011 [05:56:55] - 3
Posted by:frdelrosarioMember Since:
June 28 2011
Posts: 1
This seems to be an ideal task for a tool that drives your browser. I used seven lines of Selenium to sign on at my bank and get my balance.
coding / applescriptPrev .. Next
 
Post Reply
Home - Coding: AppleScript C Perl Shell Xcode Other
Our Telegram Group