Software >> Development >> Languages >> Perl >> How to use session cookies to login to shareinvestor.com website

my $ua = LWP::UserAgent->new(); $ua->agent('Mozilla'); my $cookie_jar = HTTP::Cookies->new( autosave => 1 ); if ( lc($useproxy) eq 'y') { $ua->proxy('http','http://proxy.exampledomain.com:8080'); } my $url = 'http://www.shareinvestor.com/sg/home.pl'; my $login_req = HTTP::Request->new(GET => $url); my $login_res = $ua->request($login_req); my $html = $login_res->content; my $form = HTML::Form->parse( $login_res->content , $login_res->base() ); $form->value('name',$username); $form->value('password',$pw); $form->value('login_once','1'); my $afterlogin_res = $ua->request( $form->click() ); $cookie_jar->extract_cookies($afterlogin_res); $cookies = $cookie_jar->{COOKIES} ; $url = sprintf "http://www.shareinvestor.com/stocks/sg_time_sales.pl?code=%s&date=%s&quantity= -1&type=1",$sgxcode,$ddddmmyy; my $loggedin_session_req = HTTP::Request->new(GET => $url); $cookie_jar->add_cookie_header($loggedin_session_req); my $loggedin_session_res = $ua->request($loggedin_session_req); open(outhandle,">$htmlout"); print $loggedin_session_res->content; print outhandle $loggedin_session_res->content; close(outhandle);

Deals @yubeshop.com