Social media Login using Python

Mostafejur Rahman
2 min readJun 26, 2021
Social media icon

Python scripting is one of the most fascinating things to do meanwhile learning python. Automation and controlling the browser is one of them. We will see how to log in to the Social media account using python and the power of selenium.

Selenium automates and controls browsers and it’s activity. Primarily, it is for automating web applications for testing purposes but is certainly not limited to just that. Web-based administration tasks can be automated as well. To see things happening automatically and saving time in doing useless tasks again and again.

We use selenium here to open the site of our requirement(in the case of Facebook) and there we inspected elements across the email box, password box, and login button to find their id.

Using find_element_by_id() function provided by selenium module, we can find the required element(username box, password box), login button)

Using send_keys() function provided by the selenium module, we will send the data into the box.

Let’s install the necessary module

pip install selenium
pip install webdriver-manager

Now import the necessary package and module for our script…

from getpass import getpass
from selenium import webdriver
from time import sleep
import webdriver_manager
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options

User Id and Password input and get the URL…

user = input('Enter Email Id: ')
pwd = input('Enter Password: ')
#pwd = getpass('Enter Password: ') ### make password invisible
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://www.facebook.com')
print("Opened facebook")
sleep(1)

Find the user name box and send data…

username_box = driver.find_element_by_id('email')
username_box.send_keys(user)
print("Email entered")
sleep(1)

Find the password box and send data

password_box = driver.find_element_by_id('pass')
password_box.send_keys(pwd)
print("Password entered")

find the login box and make an automatic click. Here we will find by name.

login_box = driver.find_element_by_name('login')
login_box.click()
print("Done")

To quite our program

input("Press anything to quit")
driver.quit()
print("Finished")

Let’s see out put…

Automated page.

--

--

Mostafejur Rahman

I have completed my Bachelor's degree from Islamic University. I am interested in Software Engineering, Machine learning, Data Science, Cyber Security.