Extract Session Cookie

Extract Session Cookie

am 23.02.2007 09:29:10 von rob.chuah

Hi guys,

I am working on a simple script using WWW:Mechanize to extract flight
details and everything works perferectly. However, I come to a road
block when I tried to extract the session cookies. I've been digging
around the internet/newsgroup for the last couple of days but still to
no avail...

When I turned on the debug routine for LWP, this is what I can see

LWP::UserAgent::new: ()
aeroperlas(debug) - Submitting initial search request
LWP::UserAgent::request: ()
HTTP::Cookies::add_cookie_header: Checking www.e-savtravel.com for
cookies
HTTP::Cookies::add_cookie_header: Checking .e-savtravel.com for
cookies
HTTP::Cookies::add_cookie_header: Checking e-savtravel.com for cookies
HTTP::Cookies::add_cookie_header: Checking .com for cookies
LWP::UserAgent::send_request: GET https://www.e-savtravel.com/wlvirtual/jdmm001.
asp?
wtipo=RT&wclase=E&wnadult=1&wnchild=0&wninfant=0&wnum=0&wnse nior=0&wrd0074a=
PAC&wrh0074a=BOC&wfc0076a=02/23/2007&wrd0074a1=BOC&wrh0074a1 =PAC&wfc0076a1=02/25
/
2007&wrd0074a2=&wrh0074a2=&wfc0076a2=&wrd0074a3=&wrh0074a3=& wfc0076a3=&wusu_rad
io=0&wop=S&wtipofare=I
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
LWP::Protocol::collect: read 471 bytes
HTTP::Cookies::extract_cookies: Set cookie ASPSESSIONIDASSTCCRQ =>
PNOPBCFDGPDDDGCNOKLBIJKA

So as can be seen, the Mechanize/LWP did handle the cookie
automatically at this line

"HTTP::Cookies::extract_cookies: Set cookie ASPSESSIONIDASSTCCRQ =>
PNOPBCFDGPDDDGCNOKLBIJKA"

Question, how do I write code using HTTP::Cookie etc to extract this
data out ?? I need to use this session cookie later (of course just a
very short interval later while the session cookie is still
effective) ..

Thanks a lot in advance ...

rgds
Rob

Re: Extract Session Cookie

am 23.02.2007 11:44:30 von paduille.4060.mumia.w+nospam

On 02/23/2007 02:29 AM, greenrob wrote:
> Hi guys,
>
> I am working on a simple script using WWW:Mechanize to extract flight
> details and everything works perferectly. However, I come to a road
> block when I tried to extract the session cookies. I've been digging
> around the internet/newsgroup for the last couple of days but still to
> no avail...
>
> When I turned on the debug routine for LWP, this is what I can see
>
> LWP::UserAgent::new: ()
> aeroperlas(debug) - Submitting initial search request
> LWP::UserAgent::request: ()
> HTTP::Cookies::add_cookie_header: Checking www.e-savtravel.com for
> cookies
> HTTP::Cookies::add_cookie_header: Checking .e-savtravel.com for
> cookies
> HTTP::Cookies::add_cookie_header: Checking e-savtravel.com for cookies
> HTTP::Cookies::add_cookie_header: Checking .com for cookies
> LWP::UserAgent::send_request: GET https://www.e-savtravel.com/wlvirtual/jdmm001.
> asp?
> wtipo=RT&wclase=E&wnadult=1&wnchild=0&wninfant=0&wnum=0&wnse nior=0&wrd0074a=
> PAC&wrh0074a=BOC&wfc0076a=02/23/2007&wrd0074a1=BOC&wrh0074a1 =PAC&wfc0076a1=02/25
> /
> 2007&wrd0074a2=&wrh0074a2=&wfc0076a2=&wrd0074a3=&wrh0074a3=& wfc0076a3=&wusu_rad
> io=0&wop=S&wtipofare=I
> LWP::UserAgent::_need_proxy: Not proxied
> LWP::Protocol::http::request: ()
> LWP::Protocol::collect: read 471 bytes
> HTTP::Cookies::extract_cookies: Set cookie ASPSESSIONIDASSTCCRQ =>
> PNOPBCFDGPDDDGCNOKLBIJKA
>
> So as can be seen, the Mechanize/LWP did handle the cookie
> automatically at this line
>
> "HTTP::Cookies::extract_cookies: Set cookie ASPSESSIONIDASSTCCRQ =>
> PNOPBCFDGPDDDGCNOKLBIJKA"
>
> Question, how do I write code using HTTP::Cookie etc to extract this
> data out ?? I need to use this session cookie later (of course just a
> very short interval later while the session cookie is still
> effective) ..
>
> Thanks a lot in advance ...
>
> rgds
> Rob
>

Are you sure you need to extract it? You didn't show any code, so it
won't be possible for people to give you specific help, but I'll bet all
you have to do is to create a persistent cookie object for
WWW::Mechanize to use.

Start->Run->"perldoc HTTP::Cookies"
Start->Run->"perldoc WWW::Mechanize"


--
Windows Vista and your freedom in conflict:
http://www.badvista.org/

Re: Extract Session Cookie

am 25.02.2007 10:26:42 von rob.chuah

Okay I am attaching a very simple code here
use WWW::Mechanize;
use LWP::Debug qw(+);

my $oneway = "0";
my $fdate = "2007-03-20";
my $tdate = "2007-04-20";
my $from = "POC";
my $to = "BOC";


my $startURL = 'http://www.aeroperlas.com';
my $mech = WWW::Mechanize->new(
agent => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1; .NET CLR 2.0.50727; .NET CLR 1.1.4322)'
);

# Format our search data
my ($depDay, $depMon, $depYear) = (split(/-| /, $fdate))[2,1,0];
my ($retDay, $retMon, $retYear) = (split(/-| /, $tdate))[2,1,0];

#Submit Initial Search
my $URL = "https://www.e-savtravel.com/wlvirtual/jdmm001.asp";
my @getData = (
'wtipo', $oneway ? "OW" : "RT",
'wclase', 'E',
'wnadult', '1',
'wnchild', '0',
'wninfant', '0',
'wnum', '0',
'wnsenior', '0',
'wrd0074a', $from,
'wrh0074a', $to,
'wfc0076a', "$depMon/$depDay/$depYear",
'wrd0074a1', $to,
'wrh0074a1', $from,
'wfc0076a1', "$retMon/$retDay/$retYear",
'wrd0074a2', '',
'wrh0074a2', '',
'wfc0076a2', '',
'wrd0074a3', '',
'wrh0074a3', '',
'wfc0076a3', '',
'wusu_radio', '0',
'wop', 'S',
'wtipofare', 'I'
);

my $query="";
for (my $i=0;$i<=$#getData;$i+=2)
{
$query .= $getData[$i] ."=". $getData[$i+1] ."&";
}

$query =~ s/&$//g;
$URL = $URL ."?". $query;
$mech->get($URL);


If you run the code tehre will be a bunch of stuff printed on the
screen. One of the line will says

"HTTP::Cookies::extract_cookies: Set cookie ASPSESSIONIDACABSRQD
=>xxxxx"

where xxxx is the session variable. Now how can I go on and extract
the value of "ASPSESSIONIDACABSRQD =>xxxxx" out ??

Thanks a lot in advance.