Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

how to read local cookies with LWP

by weihe (Initiate)
on Apr 28, 2006 at 17:47 UTC ( [id://546325]=perlquestion: print w/replies, xml ) Need Help??

weihe has asked for the wisdom of the Perl Monks concerning the following question:

in this code , i find that it can create a cookies file, and also can save cookies from vist webpage, but i think while i open a website and login with IE6.0, so the website would create a cookies in my computer. when i use LWP::UserAgent to download the webpage, it said i haven't login yet, so i want to use http::cookies to read my computer's cookies which the website have created, and while i download webpage, the website can know me. is anyone can give me a hand, thank you very much
use LWP::UserAgent; use HTTP::Cookies; $ua = LWP::UserAgent->new; $ua->cookie_jar(HTTP::Cookies->new(file => "lwpcookies.txt", autosave => 1)); # and then send requests just as you used to do $res = $ua->request(HTTP::Request->new(GET => "http://www.yahoo.no") +); print $res->status_line, "\n";

Replies are listed 'Best First'.
Re: how to read local cookies with LWP
by Corion (Patriarch) on Apr 28, 2006 at 18:34 UTC
      thanks for you answer my question,now my problem have solve. and i would like to share my code
      use LWP; use HTTP::Cookies::Microsoft; use Win32::TieRegistry(Delimiter => "/"); my $cookies_dir = $Registry-> {"CUser/Software/Microsoft/Windows/CurrentVersion/Explorer/Shell + Folders/Cookies"}; $cookie_jar = HTTP::Cookies::Microsoft->new( file => "$cookies_dir\\index.dat", 'delayload' => 1, ); my $browser = LWP::UserAgent->new; $browser->cookie_jar( $cookie_jar ); $req = HTTP::Request->new('GET',"http://www.92home.com/cgi-bin/lb5000 +/memberlist.cgi?a=4&page=1"); $res = $browser->request($req); print $browser->request($req)->as_string;
Re: how to read local cookies with LWP
by sgifford (Prior) on Apr 28, 2006 at 17:56 UTC
    Hi weihe,

    What you're asking for is very browser-specific; there's no standard for system-wide cookie storage. You'll have to figure out how the browser you're using stores cookies, either from its documentation, its source code, or by poking around and seeing what it does. Then you can find them in its store and tell LWP about them.

    IIRC, IE stores its cookies in a cookies directory somewhere in the user's settings; you can probably get the name of the directory from the registry.

      i use internet explorer 6.0, while i login the website ,it would excute this method,this code in this following,
      $namecookie = cookie(-name => "amembernamecookie", -value => "$ +inmembername", -path => "$cookiepath/", -expires => "$CookieDate"); $passcookie = cookie(-name => "apasswordcookie", -value = +> "$inpassword", -path => "$cookiepath/", -expires => "$CookieDate" +); print header(-cookie=>[$namecookie,$passcookie] , -expires=>"$EXP_MODE +" , -cache=>"$CACHE_MODES");
      and while i use lwp to load the webpage , it will use this code to read my computer's cookies about username and password, the code is
      if (! $inmembername) { $inmembername = cookie("amembernamecookie"); } if (! $inpassword) { $inpassword = cookie("apasswordcookie"); }
      as you know LWP is not support cookies by default, and though we use http::cookies to create a cookie file in the harddisk, but it is not equal to the cookies which we login the website and create by server. thanks for you reply me, how can i read the cookies or set cookies with my username and password, while i use a LWP to download the webpage ,the server can know me through the cookies value

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://546325]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-26 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found