I'm attempting to write a perl script to logon to Etrade, but I'm stuck (I
had one working until Etrade made some changes recently). Below is a script
that extracts the variables from Etrades login page, adds the user password
and userid, and then tries to login. It fails and I'm not sure what is wrong.
I'm interested if anyone has any pointers or advice.
Note that you'll have to add your own UserId and Password.
thanks,
[EMAIL PROTECTED]
use Win32::OLE;
# local variables
my $myname = "<UserId>"; #my userid (add your own)
my $mypass = "<Password>"; #my password (add your own)
my $BROWSER; #make local
my $stat; #make local
my $body; #make local
my $mystring = "junk"; #make local (eliminate warning in loop below)
my @lines1; #make local
my @lines2; #make local
my @lines3; #make local
my $i = 0; #make local
my $myline = ""; #make local
my $name = ""; #make local
my $value = ""; #make local
my $post_string = ""; #initialize the string to be posted
$BROWSER = Win32::OLE->new('InternetExplorer.Application');
#open the browser
$BROWSER->{'Visible'}=1;
#make it visible
$BROWSER->Navigate("https://trading.etrade.com/cgi-bin/gx.cgi/AppLogic+Loginpa
ge"); #get the https cookies from etrade
for($i = 0; $i < 10 && !($mystring =~ m/login_sid/); $i++) # try up to 10
times before giving up
{
do #wait until the first page finishes loading (to get the cookies) before
logging in
{
select(undef,undef,undef,0.1); #sleep 0.1 seconds (finer time resolution
than "sleep" command)
$stat=$BROWSER->{Busy}; #get the status of the browser load
}
while ($stat); #continue looping if the browser is NOT yet
done loading
# get the HTML data for extraction of login_sid
$body=$BROWSER->Document->{body}; #get the hash string
retruned by the browser
$mystring= $body->{innerHTML}; #get the HTML data from
browser
}
# get the variables for the HTML page
$mystring =~ s/>/ /g; #replace all of the ">"
characters in the HTML string with spaces
@lines1 = split /</m, $mystring; #split the lines in the
HTML page at the "<"
@lines2 = grep /[iI][nN][pP][uU][tT]/, @lines1; #grep lines containing
"input" (any mixture of upper and lower case characters)
@lines3 = grep /[nN][aA][mM][eE]/, @lines2; #grep lines containing
"name" (any mixture of upper and lower case characters)
foreach $myline (@lines3) #add the HTML variables
to the string to be posted
{
if(($name) = $myline =~ m|[nN][aA][mM][eE]=(\S+)|) { $post_string .=
"&$name" }; #get name of the variable
if($name =~ m|[uU][sS][eE][rR]|) { $post_string .=
"=$myname&userid=$myname"} #add values of the USER
variables
elsif($name =~ m|[pP][aA][sS][sS][wW][oO][rR][dD]|) { $post_string .=
"=$mypass&password=$mypass"} #add values of the PASSWORD variables
elsif($name =~ m|[lL][oO][gG][oO][nN]|) { $post_string .=
"=1&$name.x=10&$name.y=10"} #add values of the Logon variables
elsif(($value) = $myline =~ m|[vV][aA][lL][uU][eE]="([^"]+)"|)
{$post_string .= "=\"$value\""} #value quoted? if yes, then keep quoted
elsif(($value) = $myline =~ m|[vV][aA][lL][uU][eE]=(\S+)|)
{$post_string .= "=$value"}; #value unquoted? if no, then do NOT keep
quoted
}
$post_string .= '&TARGET=/cgi-bin/gx.cgi/applogic+Home?protect'; #add
variable showing where to start
$post_string =~ s/&/?/; #replace
first "&" character with "?" in post string
$BROWSER->Navigate('https://trading.etrade.com/cgi-bin/gx.cgi/AppLogic+Loginpa
ge/login.fcc' . $post_string ); #login
# debug: print out the componants of $post_string
print "\npost_string=$post_string\n\n";
@lines1 = split /&/m, $post_string;
foreach $myline (@lines1) {print "\n$myline\n"};
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl