Click here to get back home

Extract Session Cookie

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Extract Session Cookie greenrob 02-23-2007
Posted by greenrob on February 23, 2007, 3:29 am
Please log in for more thread options


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&wnsenior=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


Posted by Mumia W. on February 23, 2007, 5:44 am
Please log in for more thread options


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&wnsenior=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/

Posted by greenrob on February 25, 2007, 4:26 am
Please log in for more thread options


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.


Similar ThreadsPosted
Perl module for cookie/logon/session management with Apache May 10, 2007, 12:40 pm
HTTP::Cookie won't store sent cookie March 17, 2005, 4:28 pm
Text::Balanced to extract subs? June 15, 2006, 10:35 pm
Apache2::Cookie August 23, 2005, 12:52 am
CGI Cookie Path Question December 26, 2005, 10:53 am
mod_perl2 and APR::Request::Cookie error October 29, 2006, 3:22 pm
CGI::Session::MembersArea V 2.01 July 29, 2004, 7:14 am
CGI::Session::ExpireSessions V 1.03 July 29, 2004, 7:14 am
Announce: CGI::Session::ExpireSessions V 1.04 November 16, 2004, 10:27 am
Problems with CGI::Session in Perl August 8, 2005, 11:25 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap