Script to add new contacts automatically( inLinkedin )


This script will do the following things : 

1) will get all user url from each page in the  linkedinGroup
2) using that user url with will get the form 
3) once the form is got , it will fill the form and send sumbit 
4) have add multiple user agents  in the request headers  




==========================================================
#!/usr/bin/perl


use strict;
use warnings;
use WWW::Mechanize;
use LWP;
use JSON;
use Data::Dumper;
use Getopt::Long;
use POSIX qw/ strftime /;
use LWP::Simple;
use HTML::TreeBuilder;
use HTML::TreeBuilder::XPath;
use List::Util qw/shuffle/;
my $username = 'login id ';
my $password = ' password ';
my $loginurl=  $maiurl.'/uas/login?goback=&trk=hb_signin';

$|++;

my $mech = login_linkedin();
my $tree = HTML::TreeBuilder::XPath->new_from_content();




my @all_content = get_data($mech,$grp,"1","10");

my @all_new_linkein_users = get_linkedin_user_url($tree,@all_content) ;

send_invitation($mech,@all_new_linkein_users);




sub set_dynamic_user_agent {

my ($mech) = @_;
my @user_agents = (
   'Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.0',
   'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0',
   'Mozilla/5.0 (X11; Linux i586; rv:31.0) Gecko/20100101 Firefox/31.0',
    'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20130401 Firefox/31.0',
    'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0',
    'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0',
    'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0',
    'Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0',
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0'
);
my @shuff_user_agents = shuffle( @user_agents );
    # dynamically set custom HTTP User-agents
    $mech->add_header( 'User-agent' => $shuff_user_agents[0]);
    print  sprintf("set User-Agent : %s \n", $shuff_user_agents[0] ) ;

return $mech;
}

sub send_invitation {

my ( $mech,@all_user_url) = @_;

  for my $user_url (@all_user_url){
    sleep(2);
  $mech= set_dynamic_user_agent($mech);
 $mech -> get("${maiurl}$user_url");
# print sprintf( "User-Agent : %s\n\n",  $mech->uri() );
#<input type="radio" name="reason" value="IF" id="IF-reason-iweReconnect" class="radio-btn">
#<input type="submit" name="iweReconnectSubmit" value="Send Invitation" id="send-invite-button" class="btn-primary"/
 #$mech ->click_button( name => "iweReconnectSubmit" );

 if ( $mech->form_name("iweReconnect") ) {
    print "sending invitation : $user_url \n";
 $mech ->set_fields( 'reason' => 'IF' );
 $mech->submit();
 $mech->success or die "form  POST fail";

  } elsif ( $mech->form_name("invitation")) {
  print " invitation was already sent to $user_url sent \n" ;
  next ;

  }else {
  print "No From matched $user_url\n ";
    next;
  }

 }

}





sub get_linkedin_user_url {
    my ($tree,@all_content) = @_;
    my $all_new_linkein_users;
    for my $content  (@all_content) {
        $tree->parse($content);

        my @newconn = $tree->findnodes('//li[@class="member"');
        print "getting url  that which is not in my connection \n";
        for my $custm (@newconn){
            my @all_a_tag = $custm->look_down('_tag' => 'a'  ) ;
             my $count =  @all_a_tag;

            my $invte_link  ;

             if (   $all_a_tag[$count - 1]->attr('href') =~ m/people/ig   ) {
                $invte_link = $all_a_tag[$count - 1]->attr('href')  ;
             } else {
             next;
             }
             print $invte_link ." ---- \n";
        push ( @all_new_linkein_users, "$invte_link")  ;

  exit unless(@all_new_linkein_users);

        }
    }
return (@all_new_linkein_users);
}


sub get_data {
    my ( $mech,$url,$spage,$epage ) = @_;

    my @all_content;
    print "Getting the content form page $spage to page $epage\n";
    for my $page ($spage .. $epage ) {
        print " ----------- ${url}$page -----------------"."\n";
        sleep(1) ;
        $mech -> get ("${url}$page");
        push ( @all_content,    $mech->content()) ;
    }
    return (@all_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 ;
}

============================================================

No comments:

Other Articles

Enter your email address: