How to Automate your Facebook post using Python

Hey Guy..! welcome to another interesting python automation tutorial, Do you want to automate your Facebook posts ..? Don’t you know how to do it..? This is for you my dear followers.

If you are Digital marketing analyst or YouTuber or even blogger, i know you will definitely share your content on different platforms. The most popular social media platform is Facebook.

I wrote a script that helps you to login you to Facebook and post on your news feed. Here we need a Python selenium package to automate this task, so please download it with corresponding Chrome or Firefox Browser version.

If you don’t installed python selenium in your system then use the below command to install it.

pip install selenium

Hey, if you don’t how to use API data , please check out this tutorial, definitely it will help you.

How to work with API in Python

How to automate Facebook post using Python

Here i am giving the entire Python script to automate your Facebook post using Python.

# Auto Posting on Facebook

from selenium import webdriver
import time

email = 'Your Email Here'
pwd = 'Your Password Here'

msg = 'Your Post or Message Here'

driver = webdriver.Chrome('chromedriver.exe')


user =  driver.find_element_by_id('email')

password = driver.find_element_by_id('pass')

button = driver.find_element_by_id('u_0_b')


body =  driver.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/div[3]/div/div/div[1]/div/div/div[2]/div/div/div[3]/div/div[2]/div/div/div/div[1]')


message = driver.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/div[4]/div/div/div[1]/div/div[2]/div/div/div/form/div/div[1]/div/div[2]/div[2]/div[1]/div[1]/div[1]/div/div/div/div/div[2]/div/div/div/div')


post = driver.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/div[4]/div/div/div[1]/div/div[2]/div/div/div/form/div/div[1]/div/div[2]/div[3]/div[2]/div')


Don’t forget to give your password, email and message on requirefields. Once you execute this script you will see the magic.

It will automatically login you and post your post on news feed. you don’t need to do anything.

I hope you will love this python script, and i hope it will helps you better. Thank you.

Leave a Reply