Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/easy-google-syntax-highlighter/easy-google-syntax-highlighter.php on line 50

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/easy-google-syntax-highlighter/easy-google-syntax-highlighter.php on line 50

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 305

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 305

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 306

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 306

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 307

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 307

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 308

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 308

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 309

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 309

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 310

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 310

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 311

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 311

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 312

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 312

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 316

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 316

Warning: mysql_real_escape_string(): No such file or directory in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 317

Warning: mysql_real_escape_string(): A link to the server could not be established in /home/umeshw/techfeedlab.com/wp-content/plugins/statpress-visitors/statpress.php on line 317

Warning: Cannot modify header information - headers already sent by (output started at /home/umeshw/techfeedlab.com/wp-content/plugins/easy-google-syntax-highlighter/easy-google-syntax-highlighter.php:50) in /home/umeshw/techfeedlab.com/wp-content/plugins/wp-greet-box/includes/wp-greet-box.class.php on line 493
Facebook login using Perl and Mechanize | Technology Feed Lab

Technology Feed Lab

technology site

Facebook login using Perl and Mechanize

Posted by TechGeek on June 28, 2011

This article will explain how to login into Facebook using Perl language? We will be using WWW::Mechanize again for this. You can use mechanize library for automating interaction with websites. The mechanize supports lot of different methods to handle text, HTML or images. It also automatically stores cookies, follow redirections etc. You can even parse links, follow links or submit web based forms easily.

Accessing the Facebook homepage requires you to be a valid user and must be logged in to do further activity. Simply fetching a webpage will not work as it will redirect you to a login page since you are not authenticated to Facebook. So you need to store credential cookies and will have to send that cookies on each requests. For this, we will use another Perl module called HTTP::Cookies. The method will be,

$cookie_jar = HTTP::Cookies->new

The above method will save our cookies. Here is the complete code for Facebook login,
-----------------------------------------
#!/usr/bin/perl -w

use strict;
use WWW::Mechanize;
use HTTP::Cookies;

my $url = "http://www.facebook.com";
# credentials
my $username = 'Enter User Name';
my $password = 'Enter Password';

my $mech_request;

sub login
{
$mech_request = WWW::Mechanize->new(autocheck => 0);
$mech_request->cookie_jar(HTTP::Cookies->new());
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;
}

#access Facebook URL's after Login
sub fb_pages()
{
my $url = shift;
my $res = $mech_request->get($url);
$mech_request->get($url);
my $data = $mech_request->content();
print $data;
}

# Start - Login to Facebook
my $data = login();
print $data;

# Now you have logged in and saved a cookie
# access anything

#my $page_url = "http://www.facebook.com/games?ap=1";
# fb_pages($page_url);

-----------------------------------------

 

pixel Facebook login using Perl and Mechanize

Leave a Comment

Your email address will not be published. Required fields are marked *

* Copy This Password *

* Type Or Paste Password Here *

CommentLuv badge