How To Send Message to Multiple Friends on Facebook

I recently programmed Python scripts that send a predefined message to all my Facebook friends. The friend.py script detects all the friend links and returns them to send_message_fb.py as a list. The config.py script contains the links of the friends that should be excluded from receiving the message. The message is also defined in the config.py file. Finally, the send_message_fb.py script sends the message sequentially to the friends. To emulate user interaction with a web browser I use Selenium WebDriver.

Selenium WebDriver is a testing tool used to automate the testing of web applications. It is one of the components of the Selenium family, which also includes Selenium IDE, Selenium Client API, Selenium Remote Control and Selenium Grid. Selenium supports many programming languages such as Java, Python, C#, Ruby, Perl, and also web browsers such as Google Chrome, Mozilla Firefox, Internet Explorer, Safari.

I prefer Google's Chrome browser because it's widely used, so it's quite likely that you can use my script without having to install Chrome or Chromium. You just need to download the ChromeDriver version which should match your Chrome browser version.

ChromeDriver is a separate executable that Selenium WebDriver uses to control Chrome. It is maintained by the Chromium team with help from WebDriver contributors. ChromeDriver expects you to have Chrome installed in the default location for your platform.

Using Scripts:

  1. Download the scripts - config.py, friend.py and send_message_fb.py from the Download section of this blog (Networking & Servers) and store the files to the same directory.
  2. Download the ChromeDriver binary for your platform here.  ChromeDrive must match your Chrome version.
  3. Edit the config.py file and change the path to reflect the location of the ChromeDriver.
  4. Change the username and password in the config.py file to match your FB credentials. You can also define there the links of your friends that you want to exclude from receiving messages. The links must be separated by a comma.
  5. Run the script send_message_fb.py from the command line:

$ python3 ./send_message_fb.py

Disclaimer:

I successfully tested the script and sent a predefined message to 70 friends (April 2022). However, since the FB page may change later, the sending may not work as expected.

 

 

 

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.