-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathscript.py
40 lines (36 loc) · 1.6 KB
/
script.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
32
33
34
35
36
37
38
39
40
# Program to send bulk messages through WhatsApp web from an excel sheet without saving contact numbers
# Author @inforkgodara
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from time import sleep
import pandas
excel_data = pandas.read_excel('Recipients data.xlsx', sheet_name='Recipients')
count = 0
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://web.whatsapp.com')
input("Press ENTER after login into Whatsapp Web and your chats are visiable.")
for column in excel_data['Contact'].tolist():
try:
url = 'https://web.whatsapp.com/send?phone={}&text={}'.format(excel_data['Contact'][count], excel_data['Message'][0])
sent = False
# It tries 3 times to send a message in case if there any error occurred
driver.get(url)
try:
click_btn = WebDriverWait(driver, 35).until(
EC.element_to_be_clickable((By.CLASS_NAME, '_3XKXx')))
except Exception as e:
print("Sorry message could not sent to " + str(excel_data['Contact'][count]))
else:
sleep(2)
click_btn.click()
sent = True
sleep(5)
print('Message sent to: ' + str(excel_data['Contact'][count]))
count = count + 1
except Exception as e:
print('Failed to send message to ' + str(excel_data['Contact'][count]) + str(e))
driver.quit()
print("The script executed successfully.")