sonal has asked for the wisdom of the Perl Monks concerning the following question:
I am using mechanize and logging into the facebook also save the cookiesand fetch the data from $page_url. but next time when I try to fetch $pageurl, it will not give me proper result and showed me as logged out.Please let me know how can I reuse the cookies file next time instead of logging in again and again
use strict; use warnings ; use WWW::Mechanize; use HTTP::Cookies; my $url = "http://www.facebook.com"; my $username = 'XXXXXXXX' ; my $password = 'XXXXXXXX' ; my $mech_request; my $data = login() ; my $page_url = "http://www.facebook.com/profile.php?id=100001726191116 +" ; my $author_data = fb_pages( $page_url ) ; sub login{ my $fname = "fbkCookies.dat" ; $cookie_jar = HTTP::Cookies->new( file=>$fname, autosave=>1, ignore_di +scard=>1 ) ; cookie_jar->save( $fname ); + $mech_request = WWW::Mechanize->new( autocheck => 0 ) ; $mech_request->cookie_jar( $cookie_jar ) ; + my $res = $mech_request->get( $url ) ; $mech_request->get( $url ) ; $mech_request->form_name( 'menubar_login' ) ; $mech_request->field( email => $username ) ; $mech_request->field( pass => $password ) ; $mech_request->click() ; my $contents = $mech_request->content() ; return $contents ; } sub fb_pages { my $url = shift ; my $res = $mech_request->get( $url ) ; $mech_request->get( $url ) ; my $data = $mech_request->content() ; return $data; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to reuse login info from cookies after logged first time in facebook and do the required search
by marto (Cardinal) on May 03, 2012 at 12:51 UTC | |
by Anonymous Monk on May 04, 2012 at 02:23 UTC | |
by marto (Cardinal) on May 04, 2012 at 08:49 UTC |