Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

whatsapp online tracker python script

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
import os

# XPath selectors
NEW_CHAT_BTN = '/html[1]/body[1]/div[1]/div[1]/div[1]/div[3]/div[1]/header[1]/div[2]/div[1]/span[1]/div[2]/div[1]/span[1]'
INPUT_TXT_BOX = '/html[1]/body[1]/div[1]/div[1]/div[1]/div[2]/div[1]/span[1]/div[1]/span[1]/div[1]/div[1]/div[1]/label[1]/div[1]/div[2]'
ONLINE_STATUS_LABEL = '/html[1]/body[1]/div[1]/div[1]/div[1]/div[4]/div[1]/header[1]/div[2]/div[2]/span[1]'

# Replace below with the list of targets to be tracked
TARGETS = {'"contactName1"': 'phoneNumber1', '"contactName2"': 'phoneNumber2'}

# Replace below path with the absolute path
browser = webdriver.Chrome(r'pathtoyourwebdriverchromedriver.exe')

# Load Whatsapp Web page
browser.get("https://web.whatsapp.com/")
wait = WebDriverWait(browser, 600)

while True:
    # Clear screen
    os.system('cls')

    # For each target
    for target in TARGETS:
        tryAgain = True

        # Wait untill new chat button is visible
        new_chat_title = wait.until(EC.presence_of_element_located((By.XPATH, NEW_CHAT_BTN)))

        while (tryAgain):
            try:
                # Click on new chat button
                new_chat_title.click()

                # Wait untill input text box is visible
                input_box = wait.until(EC.presence_of_element_located((By.XPATH, INPUT_TXT_BOX)))

                time.sleep(0.5)

                # Write phone number
                input_box.send_keys(TARGETS[target])

                time.sleep(1)

                # Press enter to confirm the phone number
                input_box.send_keys(Keys.ENTER)

                time.sleep(5)
                tryAgain = False

                try:
                    try:
                        browser.find_element_by_xpath(ONLINE_STATUS_LABEL)
                        print(target + ' is online')
                    except:
                        print(target + ' is offline')
                    time.sleep(1)
                except:
                    print('Exception 1')
                    time.sleep(10)
            except:
                print('Exception 2')
                time.sleep(4)
Comment

PREVIOUS NEXT
Code Example
Python :: python pyowm 
Python :: split datetime to date and time pandas 
Python :: python count array length 
Python :: run exe from python 
Python :: check how many times a substring appears in a string 
Python :: pyqt disable maximize button 
Python :: python change character in string 
Python :: current date and time into timestamp 
Python :: how to remove quotes from a string in python 
Python :: pandas column filter 
Python :: how to get the author on discord.py 
Python :: xticks label matplotlib 
Python :: python find equal rows of two numpy arrays 
Python :: django create object with default today date 
Python :: how to execute bash commands in python script 
Python :: python email 
Python :: count different values in list python 
Python :: check python version windows 
Python :: pandas change column dtype 
Python :: get index of value in list if value meet condition python 
Python :: python factorial 
Python :: how to make a button in python turtle 
Python :: To visualize the correlation between any two columns | scatter plot graph 
Python :: how to code python 
Python :: python check if website is reachable 
Python :: google translator api pyhton 
Python :: is string mutable in python 
Python :: ppcm python 
Python :: python3 shebang 
Python :: how to install pyinstaller 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =