Hi, it's Ankur.
This post is about powerful web automation library called Selenium and its implementation in python to login automatically into different famous social media sites.Sometimes its worth time taking to login everytime into your social media and remembering credentials. Web automation is one of the most hottest fields now a days used by a large scale of organization to automate their different processes.
But for todays article we are considering only Linkedin to get automatically logged into it with the help of web automation.
Tools/libraries which are going to use are as follows
python,selenium,time,chrome driver
Follow the following Steps to start
1.Download Chrome webdriver to enable Selenium to connect with your browser.
2.GOTO http://chromedriver.chromium.org/downloads
3.Downlaod the required version of Webdriver according to your Browser Version
4.Now extract the downloaded zip file and copy the .exe file to the Python main directory
Let's Start Coding
a. Create a Linkedin.py file
b. import the libraries (Assuming you have already installed the above mentioned libraries)
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
c. Make a class named as Linkedin and make a function inside it that takes your username,password as arguement to login.
class Linkedin:
def __init__(self,username,password):
self.username=username
self.password=password
self.bot=webdriver.Chrome(PATH_TO_BROWSER_DRIVER)
Give path of your chrome driver in webdriver.chrome
d. Make a function inside the same class named as login
def login(self):
bot=self.bot
bot.get("https://www.linkedin.com/uas/login")
time.sleep(3)
email=bot.find_element_by_id("username")
email.send_keys(self.username)
password=bot.find_element_by_id("password")
password.send_keys(self.password)
time.sleep(3)
password.send_keys(Keys.RETURN)
Here bot.get will get the url of linkedin and after 3 second bot will find element by id "username" where it will fill your provided username.similarly for password it does same.
e. Now call the above class and press login
load=Linkedin("your_email","your_password")
load.login()
f. Now all done type the following command to execute
$ python3 Linkedin.py
similarly you can use the same concept to auto login into several social media account.
I hope this article will help people who want to learn about web automation.
And I hope the dev.to community grows more!
Top comments (2)
This is really cool! I built a similar thing for LinkedIn (not based on Selenium though) - might be helpful π github.com/tomquirk/linkedin-api
well organised content, Explanation is very clear.