Welcome folks today in this tutorial we will be making a whatsapp bot in python
which will send automatically messages to multiple groups and people
at same time. All the source code of the application will be shown below
Get Started
In order to get started we need to install the following libraries by issuing the pip command
pip install selenium
After installing this library make sure you install your chrome version driver
by this link
And after that make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By import time # Replace below path with the absolute path # to chromedriver in your computer driver = webdriver.Chrome('chromedriver.exe') driver.get("https://web.whatsapp.com/") wait = WebDriverWait(driver, 600) # Replace 'Friend's Name' with the name of your friend # or the name of a group target = 'Programming Life' # Replace the below string with your own message string = "Hi My name is Gautam and this message was sent by whatsapp bot which is developed in python" x_arg = '//span[contains(@title,' + target + ')]' group_title = wait.until(EC.presence_of_element_located(( By.XPATH, x_arg))) group_title.click() inp_xpath = '//div[@class="input"][@dir="auto"][@data-tab="1"]' input_box = wait.until(EC.presence_of_element_located(( By.XPATH, inp_xpath))) for i in range(100): input_box.send_keys(string + Keys.ENTER) time.sleep(1) |
Now just replace your group name or contact name
and also replace your message in the respective fields and then run this script by executing the below command
python app.py
When you execute this a chrome browser window will automatically open the whatsapp web
and then you need to scan your qr
code from your mobile whatsapp and then it will send the message successfully.