Hi everybody.  I'm working on this idea I had for a better online grocery
shopping interface.  I won't go into the Big Picture here.
For now, I'm trying to get some data from the homeruns site, using
LWP::UserAgent.  Somehow, homeruns is making it very difficult for me to
access their pages using perl.  At first I thought it was just a matter of
storing and spitting out the correct cookies, but it seems to be more
involved than that.  Their site is built with asp, and requires logging in
first.  A user can log in with just a zip code, just to try it out, and
that's what I'm trying to do with my script.

What I'm trying to do below is to log in using POST, store the cookie, and
pass it back with my next POST request for some actual data, but I keep
getting kicked back to the login page.  Any ideas?

On an unrelated note, I just participated in a Brain and Cognitive Science
experiment, and got an MRI of my brain.  It's kind of cool, in a spooky and
squishy way, so if you want to see what's going on in here, you can check
it out at www.joelman.com/mybrain :)

TIA

-------------------------------------Perl
below-----------------------------------------

use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use HTTP::Cookies;
use CGI;

$login = "http://601.homeruns.com/noframes/browsezip.asp?save=1&zipcode=02144";

$url =
"http://601.homeruns.com/noframes/product.asp?aisle_id=080&sctn_id=002&sctna
me=Baking+Ingredients&dept_id=All&catname=Baking+Ingredients";

  $ua = LWP::UserAgent->new;
  $cookie_jar = HTTP::Cookies->new(file => "homerunscookies.txt",
                                     autosave => 1, ignore_discard => 1);
$ua->agent("Mozilla/5.0");

$login = POST "http://601.homeruns.com/noframes/browsezip.asp",
    [save => '1', zipcode => '02144'];

$data = POST "http://601.homeruns.com/noframes/product.asp",
    [aisle_id => '080', sctn_id => '002', sctname => 'Baking+Ingredients',
dept_id => 'All', catname => 'Baking+Ingredients'];

$response = $ua->request($login);
$response = $ua->request($login1);

open (HRDATA, ">homeruns_welcome.html");
print HRDATA $response->content;
close HRDATA;

$cookie_jar->extract_cookies($response);
$cookie_jar->save( "homerunscookies.txt");

$cookie_jar->add_cookie_header($data);

# Just write result to file for now ...
open (HRDATA, ">homeruns_bakery.html");
print HRDATA $ua->request($data)->content;
close HRDATA;
---------------------------------------------------------------------
Joel Gwynn                              Designers' CADD Company, Inc.
A bus station is where a bus stops. 
A train station is where a train stops. 
So now you know why they call this a workstation... 

Reply via email to