Я пытаюсь отправить изображение с помощью whtasapp с помощью автоматического python скрипта. Но он отправляет изображение только на последний номер телефона, который я указываю в списке. Я использовал код для отправки сообщения на тот же список номеров и его работы. Я не знаю, где я ошибаюсь. Кто-нибудь может мне в этом помочь?
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.options import Options
import socket
import getpass
import os
user = getpass.getuser()
# print(user)
# os.system("pause")
filepath = input('Enter your filepath (images/video): ')
no_of_message=1
moblie_no_list=[919523050695,918679434243]
def element_presence(by,xpath,time):
element_present = EC.presence_of_element_located((By.XPATH, xpath))
WebDriverWait(driver, time).until(element_present)
def is_connected():
try:
# connect to the host -- tells us if the host is actually
# reachable
socket.create_connection(("www.google.com", 80))
return True
except :
is_connected()
driver = webdriver.Chrome(executable_path="C:/Users/kesood/Downloads/chromedriver_win32/chromedriver.exe")
driver.get("http://web.whatsapp.com")
sleep(10) #wait time to scan the code in second
def send_whatsapp_msg(phone_no,image):
driver.get("https://web.whatsapp.com/send?phone={}&source=&data=#".format(phone_no))
try:
driver.switch_to.alert()
except Exception as e:
pass
try:
element_presence(By.XPATH,'//*[@id="main"]/footer/div[1]/div[2]/div/div[2]',30)
attachment_box = driver.find_element_by_xpath('//div[@title = "Attach"]')
attachment_box.click()
image_box = driver.find_element_by_xpath(
'//input[@accept="image/*,video/mp4,video/3gpp,video/quicktime"]')
image_box.send_keys(filepath)
sleep(3)
send_button = driver.find_element_by_xpath('//span[@data-icon="send"]')
send_button.click()
global no_of_message
for x in range(no_of_message):
send_button.send_keys(image)
send_button.send_keys("\n")
except Exception as e:
print("Telefone Invalido:"+str(phone_no))
for moblie_no in moblie_no_list:
try:
send_whatsapp_msg(moblie_no,filepath)
except Exception as e:
sleep(10)
is_connected()```