Pari Digital Marketing

success behind you


Amazon Summer Offers - Get 80% Discount

Wednesday 18 December 2019

Send whatsapp message using python

Stay Safe Wear Mask, Protect Your Self from COVID-19 Thanks For Visit My Website
Have you ever wished to automatically wish your friends on their birthdays, or send a set of messages to your friend ( or any Whastapp contact! ) automatically at a pre-set time, or send your friends by sending thousands of random text on whatsapp! Using Browser Automation you can do all of it and much more!
Send whatsapp message using python
First you must install these:-

1) Python Bindings for Selenium ( Browser Automation software )

pip install selenium

2) Chrome webdriver
Download Chrome driver from here: Chromedriver download page ( choose your specific version )
Extract it in a known location , as we need the location later

If you get stuck somewhere, Refer To the documentation: Documentation link

3) Chromium Web Browser( Open source version of chrome browser )

sudo apt-get install chromium-browser

That’s it! You are all set.

Lets dive in right away-

from selenium import webdriver
from import WebDriverWait
from import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from import By
import time
# Replace below path with the absolute path
# to chromedriver in your computer
driver = webdriver.Chrome('/home/saket/Downloads/chromedriver')
wait = WebDriverWait(driver, 600)
# Replace 'Friend's Name' with the name of your friend 
# or the name of a group 
target = '"Friend\'s Name"'
# Replace the below string with your own message
string = "Message sent using Python!!!"
x_arg = '//span[contains(@title,' + target + ')]'
group_title = wait.until(EC.presence_of_element_located((
    By.XPATH, x_arg)))
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)
Keep your mobile phone with you.
Choose whatsapp web from the top bar in whatsapp(3 dots)
and Scan QR code from your mobile
and Enjoy

Feel free to modify the code. Try to :

Text Multiple Groups at once
Send the messages from a predefined list of messages randomly or
Send complete random text.
Comment below about your experience!

When it comes to browser automation, this is just the tip of the iceberg. Will write more articles on browser automation to give you a glimpse of its power!

Note: Please use this script only for educational purposes

1 comment:

New For You Open It

Popular Posts