Python
Python String format() Explain with EXAMPLES
What is Python String format()? Python String format() is a function used to replace, substitute, or...
In order to log into Facebook using Python, you need to use Selenium (a web automation tool). Selenium can automate and control a browser and click, fill text, submit buttons that appear on various websites.
To log in to Facebook, we will use a Python Script that drives Selenium. The Selenium Python Script will
Here is a quick video on the system will work.
Note: You can configure Selenium to use any browser like Chrome, Safari, IE, etc. In this tutorial, we will use FireFox
What do you need to Install?
Code to Login into Facebook using Python
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
# Step 1) Open Firefox
browser = webdriver.Firefox()
# Step 2) Navigate to Facebook
browser.get("http://www.facebook.com")
# Step 3) Search & Enter the Email or Phone field & Enter Password
username = browser.find_element_by_id("email")
password = browser.find_element_by_id("pass")
submit = browser.find_element_by_id("loginbutton")
username.send_keys("This email address is being protected from spambots. You need JavaScript enabled to view it.")
password.send_keys("yourpassword")
# Step 4) Click Login
submit.click()
Explanation of the code
Sample Output
The values of the username "guru99" and password entered.
The Facebook page will login with email and password. Page opened (see image below)
❓ What else can I use except Selenium to login to Facebook using Python?
You can use the Facebook API to write Python Scripts to log into Facebook from your application
👉 Is there an alternative to using Selenium for Login to Facebook using Python?
There are many alternatives to Selenium that you can check here Though some of the tools may not support Python
What is Python String format()? Python String format() is a function used to replace, substitute, or...
Dictionary is one of the important data types available in Python. The data in a dictionary is...
What is a CSV file? A CSV file is a simple type of plain text file which uses a specific structure...
What are the modules in Python? A module is a file with python code. The code can be in the form...
len() is a built-in function in python. You can use the len() to get the length of the given...
The concept of loops is available in almost all programming languages. Python loops help to...