NameError Traceback (most recent call last)
Input In [10], in <cell line: 72>()
58 def paste_content(self, navegador, el, content):
59 navegador.execute_script(`
60 f'''
61 const text = `{content}`;
(...)
69 ''',
70 el)
---> 72 if _name_ == "_main_":
74 zap = ZapZap()
75 zap.EnviarMsg()`
NameError: name '_name_' is not defined
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
import configparser
class ZapZap:
def __init__(self):
self.endereco = 'https://api.whatsapp.com/send?phone=55'
self.numeros = [11941194455]
self.timer = 5
self.timer2 = 25
config = configparser.ConfigParser()
config.read('texto.ini', encoding='UTF-8')
self.mensagem = config['texto']['mensagem']
self.profile = config['caminho']['profile']
def EnviarMsg(self):
servico = Service(ChromeDriverManager().install())
options = Options()
options.add_argument(self.profile)
navegador = webdriver.Chrome(service=servico, options=options)
for n in self.numeros:
navegador.get(self.endereco + str(n))
navegador.maximize_window()
time.sleep(self.timer)
wait = WebDriverWait(navegador, 10)
# Primeiro botão para iniciar conversa
wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="action-button"]/span'))).click()
time.sleep(self.timer)
# Segundo botão para continuar no WhatsApp Web
wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="fallback_block"]/div/div/h4[2]/a/span'))).click()
time.sleep(self.timer2)
# Clicar no campo de digitação
input_el = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[1]/div/div[1]/p')))
input_el.click()
time.sleep(self.timer)
# Colar a mensagem
self.paste_content(navegador, input_el, self.mensagem)
time.sleep(self.timer)
wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[2]/button/span'))).click()
time.sleep(self.timer)
def paste_content(self, navegador, el, content):
navegador.execute_script(
f'''
const text = `{content}`;`
const dataTransfer = new DataTransfer();
dataTransfer.setData('text', text);
const event = new ClipboardEvent('paste', {{
clipboardData: dataTransfer,
bubbles: true
}});
arguments[0].dispatchEvent(event)
''',
el)
if __name__ == "__main__":
zap = ZapZap()
zap.EnviarMsg()
Input In [5]
zap = ZapZap()
^
IndentationError: expected an indented block