Sending WhatsApp message to bulk recipients using python

Sending WhatsApp message to bulk recipients using python

·

2 min read

Sending bulk messages on WhatsApp using Python and Selenium is possible, but it is against WhatsApp's terms of service to do so. WhatsApp's terms of service state that automated messages may only be sent for non-promotional purposes, such as sending weather alerts or notifications from a delivery tracking service. It is against the terms of service to use automated messages for promotional purposes, such as sending marketing messages or advertisements.

If you still want to proceed with sending bulk messages on WhatsApp using Python and Selenium, you will need to use the Selenium library to control a web browser and interact with the WhatsApp web interface. This will require you to scan a QR code with your phone to log into WhatsApp on the web.

Install selenium and have chrome deliver on directory where the script is.

from selenium import webdriver
import time
import os
from selenium.webdriver.chrome.options import Options

# Set up the web driver
driver_path = os.path.join(os.path.abspath(os.getcwd()), r'chromedriver.exe')
driver = webdriver.Chrome(options=Options,executable_path=driver_path)
web_url = "https://web.whatsapp.com"
driver.get(web_url)
time.sleep(30)

# add recipients list. Replace with exact Name in your contacts list
recipients = ["Recipient 1","Recipient 2","Recipient 3"]

# add your message
msg = "Your message"

for recipient in recipients:
    # click recipient name
    driver.find_element_by_xpath('//span[@title= "{}"]'.format(recipient)).click()
    # send message to message box
    msg_box = driver.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[1]/div/div[1]/p')
    msg_box.send_keys(msg)
    # clicking send button
    button = driver.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[2]/button')
    button.click()

Note: It is important to note that sending bulk messages on WhatsApp using Python and Selenium is against the platform's terms of service and may result in your account being banned. You should only use automated messages for non-promotional purposes, and even then, you should proceed with caution.

Did you find this article valuable?

Support Codeviz by becoming a sponsor. Any amount is appreciated!