Automated Facebook Page Post

Three days a week I post a YouTube link to a Facebook page for a client and I wanted to see how I could automate this process.

I found a few things online about being able to use the Python programming language together with a framework called Selenium. What this enables you to do is create an automated executable program/script which can work with Google Chrome Driver in order to open pages and web scrape through selecting elements on the webpage by things like their class and id selectors, doing all of the above on its own.

At first, I wanted to get the script to go to the specific youtube channel and save the link under a variable firstVideoURL and then open a new tab for Facebook where I would log into my account. After that, I wanted to navigate to the specific Facebook page and then create a post by pasting the firstVideoURL in the “Write a post…” text box. Unfortunately, I wasn’t able to do this as I wasn’t able to find the selector ID for the text box.

I found some information online that in order to post to a Facebook page I needed an API key from the developer’s page on Facebook. Looking at the Facebook documentation I created a project in PyCharm and wrote the code shown in my GitHub Project.

Follow these steps to complete it yourself:

  • Download/Install PyCharm
  • Download/Install Selenium
  • Download/Install Chrome Driver
  • Download/Clone my “Automated Facebook Posting with Python & Selenium” GitHub Repository
  • Replace variables in the file
  • Run the file
  • Watch the magic happen!

The code in this project can be run using the program called PyCharm and the Selenium framework. Visit my GitHub project called Automate Facebook Posting with Python and Selenium to download the project and try it out yourself.