Python 3 Selenium Whatsapp Bot Automation Script to Send Messages to Contacts Using CSV File

 

How to Automate WhatsApp Messaging Using Selenium and CSV Files

 

Automating repetitive tasks can save time and reduce errors. In this tutorial, we’ll demonstrate how to send WhatsApp messages in bulk

using Python, Selenium, and a CSV file. Follow the steps below to build and run this automation script.

 


Step 1: Install Required Dependencies

 

Before starting, ensure you have Python installed on your system. Then, install the required libraries using pip:

 

pip install selenium

 

Also, download the Chrome WebDriver that matches your browser version from here and add it to your system’s PATH.

Step 2: Prepare Your CSV File

 

Create a CSV file named contacts.csv in the same directory as your script. This file should contain two columns:

 

  1. Phone Number: The recipient’s phone number (with country code, e.g., 911234567890 for India).
  2. Message: The message text to be sent.

 

Example content of contacts.csv:

 

 

Step 3: Write the Python Script

 

Below is the complete Python script to send WhatsApp messages:

 

app.py

 

 

 

Step 4: Run the Script

 

  1. Save the script as whatsapp_automation.py in the same directory as your contacts.csv file.
  2. Open a terminal or command prompt and run the script:

 

python whatsapp_automation.py

 

  1. When the script opens WhatsApp Web, scan the QR code with your mobile WhatsApp app.
  2. The script will send messages to the contacts listed in contacts.csv one by one.

 

Step 5: Adjust Sleep Timings

 

If your internet connection is slow or WhatsApp Web takes longer to load, increase the sleep times (time.sleep()) in the script. This ensures that messages are sent correctly without interruptions.

 


Best Practices

  1. Respect Privacy: Use this script responsibly and ensure you have consent to message the recipients.
  2. Rate Limiting: Avoid sending messages too quickly to prevent being flagged by WhatsApp.
  3. Backup Your CSV File: Keep a backup of your contacts.csv file to avoid accidental data loss.

 

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

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