Skip to content

Instantly share code, notes, and snippets.

@todmephis
Last active September 5, 2024 21:37
Show Gist options
  • Save todmephis/6af565bd2c68a3a5f272a17474e1ff95 to your computer and use it in GitHub Desktop.
Save todmephis/6af565bd2c68a3a5f272a17474e1ff95 to your computer and use it in GitHub Desktop.
WhatsApp automatizacion
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
from itertools import product
def borrar_numero_completo():
search_box = driver.find_element(By.XPATH, "//div[@contenteditable='true']")
for _ in range(12):
search_box.send_keys(Keys.BACKSPACE)
time.sleep(1)
def verificar_numero_whatsapp(numero):
search_box = driver.find_element(By.XPATH, "//div[@contenteditable='true']")
search_box.clear()
search_box.send_keys(numero)
time.sleep(3)
try:
no_results = driver.find_element(By.XPATH, "//span[contains(text(), 'No results found for')]")
if no_results:
pass
except:
# Si no se encuentra el mensaje, se asume que el número está registrado
print(f"El número {numero} está registrado en WhatsApp.")
borrar_numero_completo()
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=./User_Data") # Mantener la sesión de WhatsApp Web iniciada
driver = webdriver.Chrome(options=options)
driver.get("https://web.whatsapp.com")
input("Presiona Enter después de escanear el código QR, si es necesario...")
time.sleep(10)
new_chat_button = driver.find_element(By.XPATH, "//div[@role='button' and @title='New chat']")
new_chat_button.click()
time.sleep(2)
numero_incompleto = "5255****3452"
combinaciones = product('0123456789', repeat=4)
for combinacion in combinaciones:
numero_completo = numero_incompleto.replace("****", ''.join(combinacion))
verificar_numero_whatsapp(numero_completo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment