Nonetheless, I seem to be doing what I want to do according to how others have done it, yet something is amiss. I have set up a cookie_jar and it prints out when I print it as a string, but when I do the request, it does not make it across and I get a 404. Why is the cookie not being sent as described in about 100 documents all over the web.
#!/usr/local/bin/perl -w use strict; use LWP::UserAgent; use HTTP::Cookies; use HTTP::Request::Common qw(POST GET);; use HTTP::Headers; use HTML::Parser; use URI; my $cururi; my $url; my @urls; my $sessionid; my $browser = LWP::UserAgent->new; my $email = 'xxxxxxxx'; my $password = 'xxxxxxx'; my $req; my $res; $browser->cookie_jar(HTTP::Cookies->new(file => 'cookie_jar', autosave + => 1)); my $initurl = "http://www.amazon.com/exec/obidos/flex-sign-in/ref=pd_n +fy_gw_si/"; &browserEmulation($initurl); open(CJ,"cookie_jar"); while (<CJ>) { chomp; if ($_ =~ /session-id\=\"(\d*-\d*-\d*)\"/) { $sessionid = $1; } } close(CJ); $url = "http://www.amazon.com/exec/obidos/flex-sign-in-done/$sessionid +"; $res = $browser->simple_request(POST "$url", { 'email' => $email, 'action' => 'sign-in checked', 'next-page' => 'recs/instant-recs-sign-in-standard.htm +l', 'password' => $password, 'method' => 'get', 'opt' => 'oa', 'page' => 'recs/instant-recs-register-standard.ht +ml', 'response' => 'tg/stores/static/-/goldbox/index/', }); while ($res->is_redirect) { my $u = $res->header('location') or die "missing location: ", $res +->as_string; print "redirecting to $u\n"; $res = $browser->simple_request(GET $u); } if ($res->is_success) { print $res->as_string; } else { my $cururl = $res->base->as_string; print "Error: " . $res->status_line . " $cururl\n"; print $res->as_string; } sub browserEmulation { my $starturl = shift || die "No url supplied\n"; my $baseuri = URI->new($starturl); push @urls,$starturl; my $parser = HTML::Parser->new(api_version => 3, start_h => [\&start ,"tagname, attr"]); my $page; $browser->agent("Jonzilla/666"); while( $url = shift @urls) { my $request = new HTTP::Request 'GET' => $url; my $result = $browser->request($request); # shortens Tim's correction, but he gets credit for finding the bu +g $cururi = $result->base->as_string; if ($result->is_success) { $page .= $result->as_string; $parser->parse($result->content); } else { $page .= "Error: " . $result->status_line . " URL=$url, $baseu +ri\n"; if ($result->as_string ne "") { $page .= $result->as_string; } } return $page; } sub start { my($tag,$attr) = @_; if ($tag eq 'frame' ) { my $thisuri = URI->new($attr->{src}); push @urls, $thisuri->abs($cururi); } } } sub scan_cj { if ($_[1] eq 'session-id') { $sessionid = $_[2]; } }
Edited by footpad, ~ Sun Sep 29 03:15:30 2002 (UTC) : Added <readmore> tag, per Consideration
In reply to Cookie Not Being Set by jonjacobmoon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |