Facebook Login by using Python:

Python scripting is an interesting thing in Python. Automation and controlling the browser is one of the few scripting in Python. In the current section, we will find out the process of logging into a Facebook account by using Python and the power of selenium for data science.

We will use selenium for opening the site of our need and then we will inspect the elements across password box, email box and login button for finding id of them.

  • By using the function find_element_by_id(), which is provided by the selenium module, we will be able to find out the required element( username box, password box, login button)
  • We will also be using the send_keys() function which is provided by the selenium module. This will help us to send the data containd in the box.
  1. Installation of required third party modules:Facebook Login by using Python for Data Science - PST Analytics
  2. Importing the required modules:

We need to import the following modules as they will be required in the function.

  • Selenium: It will help in the automation of the browser.
  • Time: It is there for pausing running scripts for few seconds as the browser tries detecting automation stuff when we give input too fast.
  1. We have to take the username and password as input from the user:

In this case, we will use the input() function and we will pass prompt messages as argument.

  1. Opening the browser and the required website: For opening a new window of chrome, we will useChrome(). Its object will be save in the variable named driver. Now we will use the get() function for opening Facebook website.
  2. Finding the elements for sending of data and sending input: We will be using the inspect element tool on the element of browser for which we want to find the id. In such a case, we need to inspect the username box, password box, and login button for finding the id. We will then use this id combined with selenium function find_element_by_id() for finding across web pages and save it in variables for using them later. We will then use the send_keys() for sending data across the elements found previously.
  3. Closing of browser: After following the steps given above, please quit the sessions by using driver.quit().

Facebook Login by using Python for Data Science - PST Analytics 

So, to learn more about it in python for data science, you can check this and this as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.