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; }
  • Comment on How to reuse login info from cookies after logged first time in facebook and do the required search
  • Download Code

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
      So? Anyone can spider content. If I put a robotic actuator on a keyboard with a camera at the monitor, does it still violate the useless TOS? Yes. Is it enforceable on Planet Earth? No. Swearing on a cellphone in the USA is illegal. Is it enforceable? No.

      If Facebook actually wanted to prevent spidering they would limit the number of pages per hour per user id and toss in captchas if a user goes over the limit.

        "So? Anyone can spider content."

        Apparently not anyone, hence the questions here and elsewhere on this subject.

        "Swearing on a cellphone in the USA is illegal."

        In New York state a fine of $25 can be levied for flirting. Are we descending in to a contest to list the least sensible/enforceable law?

        "If Facebook actually wanted to prevent spidering they would limit the number of pages per hour per user id and toss in captchas if a user goes over the limit."

        I'm not a Facebook user, but I know many people who are. Your solution makes no sense from a usability point of view, or from Facebook's perspective/business objectives. They provide an API for what they consider legitimate interactions with their systems. Again, this is on their terms, if you don't agree with them, don't use their service.

        While it technically possible to violate terms and conditions, SPAM peoples guestbooks and far more nefarious activities, personally I don't think this is a suitable place to provide such solutions. Just because things can be done doesn't always mean it's a good idea.