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

I found one script for accessing app info from this forum.Basically, i am accessing facebook apps and may install it automatically.

I tried to see if i get a permission dialog page by following code but it does not return the permission page rather the first page.

what facebook do is multiple redirects or meta or sends few other request and then lands the user to permission page where i need to click allow button. But i am not able to get that final permission page for many apps. Here is the code,

use strict; use WWW::Mechanize; use HTTP::Cookies; my $url = "http://www.facebook.com"; my $appurl = "http://apps.facebook.com/funmoods/"; my $username = 'mail'; my $password = 'pass'; my $mech = WWW::Mechanize->new(); $mech->cookie_jar(HTTP::Cookies->new()); $mech->get($url); $mech->form_name('menubar_login'); $mech->field(email => $username); $mech->field(pass => $password); $mech->click(); my $facebook_content = $mech->content(); # go to an app url $mech->get($appurl); my $app_content = $mech->content(); print "$app_content\n";

I don't know why mechanize does not access final loaded page. it took some time to load the permission page but mechanize always returns first source page. How i can tell mechanize to wait till it loads all the pages?

Need help thanks

Replies are listed 'Best First'.
Re: Mechanize and Facebook App
by moritz (Cardinal) on Apr 07, 2011 at 12:30 UTC
    I don't know why mechanize does not access final loaded page. it took some time to load the permission page but mechanize always returns first source page. How i can tell mechanize to wait till it loads all the pages?

    Judging from your vague description it sounds like Facebook uses Javascript to load some pages. WWW::Mechanize doesn't interpret any javascript, so that's why.

    Note that Facebook also has APIs to do stuff, which are prefered over screen scraping. See facebook for example.

Re: Mechanize and Facebook App
by marto (Cardinal) on Apr 07, 2011 at 12:55 UTC