python - web.whatsapp 没有传递机器人的消息
问题描述
我创建了一个机器人来通过 web.whatsapp 发送消息。机器人打开浏览器,打开与联系人聊天,写消息,但消息未送达
我正在使用 python 2、selenium 和 chrome.webdriver
from time import sleep
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
import socket
message_text='Ola essa é uma mensagem automatizada de Whats App escrita pelo computador e enviada em uma campanha massiva de marketing. Obrigado pela atenção' # message
no_of_message=3 # no. of time
moblie_no_list=[xxxxxxxxx] # list of phone number
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="chromedriver.exe")
driver.get("http://web.whatsapp.com")
sleep(10) #wait time to scan the code in second
def send_whatsapp_msg(phone_no,text):
driver.get("https://web.whatsapp.com/send?phone={}&source=&data=#".format(phone_no))
try:
driver.switch_to.alert().accept()
except Exception as e:
pass
sleep(5)
txt_box=driver.find_element(By.XPATH , '//*[@id="main"]/footer/div[1]/div[2]/div/div[2]')
txt_box.click()
txt_box.send_keys("oi")
sleep(2)
txt_box.send_keys(Keys.ENTER)
for moblie_no in moblie_no_list:
try:
send_whatsapp_msg(moblie_no,message_text)
except Exception as e:
sleep(10)
is_connected()
解决方案
推荐阅读
- javascript - 如何修复 Rails 'ActiveRecord::RecordNotFound(找不到没有 ID 的程序)'
- docker - 已分配 docker 映像 throws 端口的 ansible 部署
- java - 数据源详细信息作为系统属性?
- rx-swift - RxSwift:在 onNext 之后调用 onCompleted 仅提供已完成的事件
- javascript - 如何通过“to”对象中的 Redirect 道具传递功能。获取 DataCloneError
- javascript - 如何创建圆角图表?
- javascript - 如何在Javascript中将带有3个字母时区缩写的日期转换为UTC?
- r - R中未加权最小二乘估计的验证性因子分析
- reactjs - 无法读取 react-redux 中未定义的属性“对象中的某些字段”
- bash - 有没有办法可以接受用户输入并将其写入文件?