LWP::UserAgent and referer?
Rob Nagler
nagler at bivio.biz
Mon Nov 26 16:16:43 CST 2001
> Got a good example of some code I can poke?
Here's an (old) example of logging into TD Waterhouse (broker). It uses
forms and cookies. You can print the $req->as_string to see what's
being sent and $res->as_string to see what you get back.
Rob
----------------------------------------------------------------
use LWP;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Cookies;
use Data::Dumper;
my($ua) = new LWP::UserAgent;
$ua->agent("Mozilla/4.7 [en] (Win98; I)");
my($cookie_jar) = HTTP::Cookies->new;
# Get the login page and initial cookies
my($req); # = HTTP::Request->new(GET => 'https://webbroker.tdwaterhouse.com/TD/Waterhouse/ie4x/logonForm.asp');
my($res) ; # = $ua->request($req);
# $cookie_jar->extract_cookies($res);
# Post the login page with initial cookies and login cookies
sub post {
my($form) = @_;
$req = HTTP::Request->new(POST => 'https://webbroker1.tdwaterhouse.com/scripts/webbroker.dll');
$req->content_type('application/x-www-form-urlencoded');
$req->content('MfcISAPICommand=wbTransact'.$form);
print $req->as_string;
$res = $ua->request($req);
print $res->as_string;
$cookie_jar->extract_cookies($res);
}
sub get {
my($pattern) = @_;
my($uri) = $res->as_string =~ /$pattern/;
$req = HTTP::Request->new(GET =>
'https://webbroker1.tdwaterhouse.com'.$uri);
$cookie_jar->add_cookie_header($req);
print $req->as_string;
$res = $ua->request($req);
$cookie_jar->extract_cookies($res);
print $res->as_string;
}
post('&webBForm=wbLogon.mwi'
.'&Browser=ie4x'
.'&UserID=<ACCOUNT-NUMBER>'
.'&Password=<ACCOUNT-PASSWORD>'
.'&Confirm=Login');
my($sid) = $res->as_string =~ /SID=([^"&]+)/;
print "##### SID=$sid #####\n";
post('&webBForm=wbPosiHistBal.mwi'
.'&SID='.$sid
.'&AccountNo=35800440'
.'&TypesList=ALL'
.'&GetHistory=History+Of+Transactions'
.'&Days=360'
);
# get('frame src="([^"]+)"');
# get('href="([^"]+Review.Balances[^"]+)');
# get('href="([^"]+GetHistory[^"]+)');
More information about the Pikes-peak-pm
mailing list