HACK : script to get all linkedin Contact email IDs -- part 1

#!/usr/bin/perl


use strict;
use warnings;
use WWW::Mechanize;
use LWP;
use JSON;
use Data::Dumper;
use Getopt::Long;
use POSIX qw/ strftime /;
my $username = 'agnello.dsouza';
my $password = 'xxxxxxxxxxxxxx';
my $loginurl=  $maiurl.'/uas/login?goback=&trk=hb_signin';
my $json_file = '/tmp/json.data';



my $mech = login_linkedin();

#my $jdata = get_jdata($mech,$all_data);
#write_to_file($jdata,$json_file);

my $jdata = read_from_file($json_file);

my @contacts = gen_url ($jdata);

foreach (@contacts){
my $fnd_details_json = get_jdata($mech,$_);
my $email = $fnd_details_json->{'contact_data'}->{'emails_extended'}->[0]->{'email'};
next unless ( $email);
print "$email\n"
}





sub gen_url {
my $jdata= shift;
my @url ;
for my $i (@{$jdata->{'contacts'}} ){
my $uri = $maiurl.'/contacts/api/contacts/'.$i->{'id'}.'/?fields=name,emails_extended,birthday,phone_numbers,sites,addresses,company,title,location,ims,profiles,twitter,wechat,display_sources';
push (@url,  $uri );
}
return @url;
}


sub get_jdata {
my ( $mech,$url ) =@_;
$mech -> get ("$url");
return    decode_json($mech ->content()) ;
}


sub login_linkedin {
my $mech = WWW::Mechanize->new();
$mech -> cookie_jar(HTTP::Cookies->new());


$mech -> get("$loginurl");
$mech -> form_id('login');
$mech -> field ('session_key' => $username);
$mech -> field ('session_password' => $password);
$mech -> click_button (value => 'Sign In');

return $mech ;

}



sub read_from_file {
my $file = shift;
my $json;

{
  local $/; #Enable 'slurp' mode
  open my $fh, "<", "$file";
  $json = <$fh>;
  close $fh;
 }
return decode_json($json);
}

sub write_to_file {
my $data  = shift;
my $file  = shift;
open my $fh, ">", "$file";
print $fh encode_json($data);
close $fh;
}


No comments:

Other Articles

Enter your email address: