Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting session cookies to work with perl

4 views
Skip to first unread message

Nospam

unread,
Oct 24, 2006, 6:37:52 PM10/24/06
to
Is there something I need to do to allow session cookies to work with perl,
as I notice I am able to fill out a form successfully with firefox, but
can't with perl, even though all the fields were filled in properly, and
mechanize states it was successful.

use...@davidfilmer.com

unread,
Oct 24, 2006, 7:07:31 PM10/24/06
to
Nospam wrote:
> Is there something I need to do to allow session cookies to work with perl,

No, they are enabled by default in Mechanize.

But you may need to do something goofy to OBTAIN the proper cookie(s)
because of however the site is set up.

I have a script that grabs some mutual fund information. I need to be
able to grab this page:
https://example.com/parts/nav/fund_performance.cfm

But, of course, I need a cookie. So I log-in like this:

$mech->get('https://example.com/parts/login_1.html');
$mech->field('userid', 'myuserid');
$mech->field('passwd', 'mypasswd');
$mech->field('javascriptenabled', 'true'); #liar!
$mech->submit;

And I thought that would have done the trick, but I found out that I
still didn't have the cookie I needed. I looked at the site's HTML (or
I could have used the TamperData plug-in for Firefox) and discovered
that I needed to do this extra step:

$mech->get('login_2.cfm'); #this sets a cookie or something

I don't know what that login_2.cfm does - I gather it drops the needed
cookie and then does a redirect or something. But I needed to do that
in order to fully authenticate the session. I just simply get() the
page; there's no form or anything on it, so I don't need to set fields
or submit anything. The simple act of get()ting this one extra page
allowed me to obtain the needed cookie.

Then I can grab and parse the info, and be fat, dumb, and happy with
something like:

my $info =
$mech->get('https://example.com/parts/nav/fund_performance_print.cfm')
->content;

--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)

0 new messages