Skip to content

Instantly share code, notes, and snippets.

@av1m
Created October 1, 2020 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save av1m/7824f0401024b27bfe8ebdec6ed287ef to your computer and use it in GitHub Desktop.
Save av1m/7824f0401024b27bfe8ebdec6ed287ef to your computer and use it in GitHub Desktop.
Chromium Selenium Whatsapp
#!/usr/sbin/python3
# coding: utf-8
import socket
import pickle
import datetime
import time
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
moblie_no_list = ["00336101020", "003380601040"]
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()
def send_whatsapp_msg(phone_no):
global driver
driver.get("https://web.whatsapp.com/send?phone={}&source=&data=#".format(phone_no))
try:
driver.switch_to_alert().accept()
except Exception as e:
pass
try:
element_presence(By.XPATH,'//*[@id="main"]/footer/div[1]/div[2]/div/div[2]',30)
txt_box=driver.find_element(By.XPATH , '//*[@id="main"]/footer/div[1]/div[2]/div/div[2]')
txt_box.send_keys(Keys.CONTROL, 'v') # paste DONT FORGET TO COPY
txt_box.send_keys("\n")
except Exception as e:
print(e)
print("invailid phone no :"+str(phone_no))
print('confirm that you have copy the content ?'.upper())
input()
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=/home/avi/.config/chromium") #Path to your chrome profile
options.add_argument("--disable-extensions")
driver = webdriver.Chrome(executable_path="./chromedriver_linux64/chromedriver", chrome_options=options)
for moblie_no in moblie_no_list:
try:
send_whatsapp_msg(moblie_no)
print('✔️ {}'.format(moblie_no))
time.sleep(5)
except Exception as e:
print(e)
time.sleep(10)
is_connected()
driver.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment