python - 如何使用 Python 解决自动化 WhatsApp 中的问题
问题描述
当我尝试搜索我的联系人时,我的代码在列表中出现错误。
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
import time
class WhatsappBot:
def __init__(self):
# Parte 1 - A mensagem que você quer enviar
self.mensagem = "Testando"
# Parte 2 - Nome dos grupos ou pessoas a quem você deseja enviar a mensagem
self.grupos_ou_pessoas = ["Mae","Matheus", ]
self.filepath = input("Enter your filepath (images/video): ")
self.teste = "Mae"
options = webdriver.ChromeOptions()
options.add_argument('lang=pt-br')
self.driver = webdriver.Chrome(
executable_path=r'./chromedriver.exe', chrome_options=options)
def EnviarMensagens(self):
self.driver.get("https://web.whatsapp.com")
time.sleep(60)
for grupo_ou_pessoa in self.grupos_ou_pessoas:
procurar = self.driver.find_element_by_class_name("_3xpD_")
procurar.click()
procurar.send_keys(self.grupos_ou_pessoas)
time.sleep(3)
campo_grupo = self.driver.find_element_by_xpath(
f"//span[@title='{grupo_ou_pessoa}']")
time.sleep(2)
campo_grupo.click()
attachment_box = self.driver.find_element_by_xpath("//span[@data-icon = 'clip']")
attachment_box.click()
image_box = self.driver.find_element_by_xpath("//input[@accept='image/*,video/mp4,video/3gpp,video/quicktime']")
image_box.send_keys(self.filepath)
time.sleep(2)
chat_box = self.driver.find_element_by_class_name("_3FRCZ")
time.sleep(3)
chat_box.click()
chat_box.send_keys(self.mensagem)
botao_enviar = self.driver.find_element_by_xpath(
"//span[@data-icon='send']")
time.sleep(3)
botao_enviar.click()
time.sleep(3)
bot = WhatsappBot()
bot.EnviarMensagens()
我该如何解决?
解决方案
推荐阅读
- powershell - Powershell 在命令中使用 Read-Host 变量
- assembly - 设置小于立即无符号:可表示整数的范围 - MIPS
- twitter-bootstrap - Bootstrap 5 > 相册示例 > 如何确保所有卡片的宽度相同(最大 xxx 宽度和最大高度)
- reactjs - 如何在新页面中显示来自 JSON 的结果?
- python - 将特定行转置为 pandas 中的列
- c - 在不取消引用的情况下保持指针越界是否安全?
- python - 正则表达式:如何忽略连接词中的点
- c# - Unity + C#:GameObject.FindGameObjectsWithTag 不起作用?
- python - 如何调整图像大小以最终具有相同的尺寸?
- node.js - 检查 Discord.js 上特定消息的反应?