Greetings all. I'm trying to log into a site (safeway.com) to get pull some nutritional information. I can get past the initial login phase, but fail when I try to get the following page. I suspect this has something to do with not using cookies properly. Could somebody please tell me what's wrong with the following piece of code? Thanks Kretch
$| = 1 ; use warnings ; use LWP::UserAgent; use HTTP::Cookies; use HTTP::Request::Common; use MD5; use strict; use Data::Dumper ; my $cookie_jar = HTTP::Cookies->new( file => $ENV{'HOME'}."/lwp_cookies.dat", autosave => 1, ); my $ua = LWP::UserAgent->new; $ua->proxy(['https','http','ftp'] => 'myinfo@myproxy') ; $ua->cookie_jar($cookie_jar) ; $ua->agent('Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.1 +1) Gecko/20071127 Firefox/2.0.0.11') ; my $response = $ua->post( 'https://shop.safeway.com/register/registernew.asp?signin +=1&returnTo=', [ "register" => '0', "rzipcode" => '90210', "zipcode" => '90210' ] ); die ("Error:", $response->status_line) unless $response->is_success ; $number = 142100398 ; my $url = "http://shop.safeway.com/dnet/RichProductInformation.aspx? +promo_windows=0&bpn=$number"; my $request = HTTP::Request->new('GET',$url); $request->protocol('HTTP/1.1') ; my $response2 = $ua->request($request) ; open (FILE,">$number".".html") || die ("cannot open file for write\n +"); print $response2->status_line."\n"; print FILE $response2->content ; close (FILE) ;

In reply to Problems using LWP::UserAgent to log into safeway.com by kretch

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.