Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Cookiejar for www::mechanize

by Agyeya (Hermit)
on Jun 16, 2004 at 04:39 UTC ( [id://367113]=perlquestion: print w/replies, xml ) Need Help??

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

Greetings Monks!
I have searched high and low, but am not able to figure out the code to create a cookiejar for www::mechanize. I checked the CPAN documentation of WWW::Mechanize(could not understand how to create cookie jar)
Then I went to PerlDoc. There searching for www::mechanize did not turn up any results. Though, a search for "cookies" did turn up two pages of hits, but none related to www::mechanize.
I did find the code to create for LWP::UserAgent, but couldnt make that work for WWW::Mechanize

If someone would be so kind as to point me to a link for the code to create a cookiejar for www::mechanize, I shall be highly obliged
Eagerly awaiting a reply

Replies are listed 'Best First'.
Re: Cookiejar for www::mechanize
by Aragorn (Curate) on Jun 16, 2004 at 07:49 UTC
    You can create an in-memory cookie jar using the constructor of WWW::Mechanize. Using an existing cookie jar, you can use the HTTP::Cookies module. The file format this module uses is different from, for example, Mozilla. You can use HTTP::Cookies::Netscape or HTTP::Cookies::Explorer to read these browser-specific files.

    Using an existing file of cookies with WWW::Mechanize can be done as follows:

    ... my $agent = WWW::Mechanize->new(); my $cj = HTTP::Cookies->new(file => "/file/to/cookie_jar"); $agent->cookie_jar($cj); ...
    (Substitute HTTP::Cookies::Netscape or HTTP::Cookies::Explorer to use a cookie file from those browsers.

    Arjen

Re: Cookiejar for www::mechanize
by dba (Monk) on Jun 16, 2004 at 17:08 UTC
    use WWW::Mechanize; use HTTP::Cookies; my $agent = WWW::Mechanize->new(); $agent->cookie_jar(HTTP::Cookies->new);
Re: Cookiejar for www::mechanize
by PodMaster (Abbot) on Jun 16, 2004 at 06:09 UTC
    WOW!!! It would appear you don't know How to RTFM, so I suggest you visit Tutorials and read the tutorial that teaches you how.

    `perldoc WWW::Mechanize':

    ... Constructor and startup new() Creates and returns a new WWW::Mechanize object, hereafter referre +d to as the 'agent'. my $mech = WWW::Mechanize->new() The constructor for WWW::Mechanize overrides two of the parms to t +he LWP::UserAgent constructor: agent => "WWW-Mechanize/#.##" cookie_jar => {} # an empty, memory-only HTTP::Cookies obje +ct ...
    update: Apparently, your problem is you don't understand English very well. You should try getting a translator.
    use WWW::Mechanize; my $mechanize_with_a_memory_only_cookie_jar = WWW::Mechanize->new ( co +okie_jar => {} );
    update: By the way, that's the same as writing my $mechanize_with_a_memory_only_cookie_jar = WWW::Mechanize->new(); (that's the default).

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 21:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found