Home Explainer Python Script for Facebook Auto Post Bot

Python Script for Facebook Auto Post Bot

Facebook Bots,Facebook Python Auto Post Bot ,Facebook Bot,Python Script
Facebook Python Bot

How to make a Facebook bot?

Now Facebook Bot is a very popular word, everyone is now familiar with bots either directly or indirectly?

So basically, what is an Internet Bot?

Bots are basically the internet robots that make things automated using scripts. You might have seen the robots in car manufacture companies.

Step by step: How to create a Facebook Bot:

For running this on you will need

  1. Python Interpreter + Selenium
  2. Browser + Driver
  3. Some basic knowledge of programming.

Step 1: Installing Python on PC

If you are using a Windows PC, you can download the Python Interpreter from their official site. In case you are using a Linux based PC, you can install it through command prompt by “$ sudo apt-get install idle” command.

Step 2: Installing Selenium on PC

Selenium is a web browser automation tool used for testing purpose.

Command for installing: Write “pip install selenium” on the command prompt.

 Step 3: Installing web browsers driver for running the Script

You can download it via below links:

Chrome: https://sites.google.com/a/chromium.org/chromedriver/downloads
Edge: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
Firefox: https://github.com/mozilla/geckodriver/releases
Safari: https://webkit.org/blog/6900/webdriver-support-in-safari-10/

Step 4: Coding for Facebook Bot

Facebook Bot, Facebook Python Bot,Python Script for Facebook Auto Post Bot
Facebook Bot

Make sure Web-driver and code are saved in same the same folder. 

Now coming to the main part, here we will coding staff with Python and Selenium.

  • Importing the necessary item for Script.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.common.exceptions import NoSuchElementException
import time

It will import everything that is needed for running the script.

  •  Initiating the web browsers and opening Facebook URL(Uniform Resource Locator).

driver = webdriver.Chrome("C:\\Users\\User\\Desktop\\chromedriver.exe")
print("Opened facebook...")

Above code will open the Chrome browsers with the help of driver that we recently installed on PC. The second line of above code will lend us to Facebook login page.

  • Entering login ID and password for the Facebook Bot.

email = driver.find_element_by_xpath("//input[@id='email' or @name='email']")
print("Email Id entered...")
password = driver.find_element_by_xpath("//input[@id='pass']")
print("Password entered...")

Don’t get confused with syntax, driver.find_element_by_xpaththis is one of the predefined syntaxes by selenium and "//input[@id='email' or @name='email']"this is something you can see on your screen by ctrl+shift+i on the keyboard.

  •  Login to Facebook using Selenium facebook bot.

button = driver.find_element_by_xpath("//button[@id='loginbutton']")
print("FB opened")

This will open your Facebook profile.

  • The final step, Posting on the wall by Script using Facebook Bot.(

statusbox.send_keys("Bot is typing here");
print("Status trying")
postbutton = driver.find_element_by_xpath("//button[contains(.,'Post')]")
print("post done")

The script is done.

READ  What is Bitcoin and Cryptocurrency

Whole code- Github.com/Satyampd

Once you are done with coding, try to run code using Python IDLE.

If you want to learn more about Selenium: http://www.seleniumhq.org/docs/

If you want to learn more about Python: https://docs.python.org/3.5/tutorial/

Any doubt or suggestion make sure to comment below.




  1. […] Though many us do not know about it, we had used it many times for our assignment and works. Quora is a platform where people ask questions and get the answer from some other fellow Quora users. When people like your answer they upvote it, similar Like button on Facebook. […]

Leave a Reply

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