-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.py
57 lines (51 loc) · 2.06 KB
/
main.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Packages
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
# Config
login_time = 30 # Time for login (in seconds)
new_msg_time = 5 # TTime for a new message (in seconds)
send_msg_time = 5 # Time for sending a message (in seconds)
country_code = 91 # Set your country code
action_time = 2 # Set time for button click action
image_path = 'image.png' # Absolute path to you image
# Create driver
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
# Encode Message Text
with open('message.txt', 'r') as file:
msg = file.read()
# Open browser with default link
link = 'https://web.whatsapp.com'
driver.get(link)
time.sleep(login_time)
# Loop Through Numbers List
with open('numbers.txt', 'r') as file:
for n in file.readlines():
num = n.rstrip()
link = f'https://web.whatsapp.com/send/?phone={country_code}{num}'
driver.get(link)
time.sleep(new_msg_time)
# Click on button to load the input DOM
if(image_path):
attach_btn = driver.find_element(By.CSS_SELECTOR, '._1OT67')
attach_btn.click()
time.sleep(action_time)
# Find and send image path to input
msg_input = driver.find_elements(By.CSS_SELECTOR, '._2UNQo input')[1]
msg_input.send_keys(image_path)
time.sleep(action_time)
# Start the action chain to write the message
actions = ActionChains(driver)
for line in msg.split('\n'):
actions.send_keys(line)
# SHIFT + ENTER to create next line
actions.key_down(Keys.SHIFT).send_keys(Keys.ENTER).key_up(Keys.SHIFT)
actions.send_keys(Keys.ENTER)
actions.perform()
time.sleep(send_msg_time)
# Quit the driver
driver.quit()