What are some Python-WhatsApp tricks?
*Python program to check user status (online/offline) from recent chats.
- Uses Selenium Web Driver
- Need to scan WhatsApp Web QR code
- Generates an excel file stored with the statuses ;)
- Has a green background for people which are online
- Flaw: Shows online for group (though it can be removed easily)
Code:
- from selenium import webdriver
- from selenium.webdriver.common.keys import Keys
- from selenium.common.exceptions import NoSuchElementException
- from openpyxl import Workbook
- from openpyxl.styles import PatternFill
- import time
- workbook = Workbook()
- sheet = workbook.active
- browser = webdriver.Chrome(executable_path=r"F:\software\chromedriver_win32\chromedriver.exe")
- //enter your driver path above
- browser.get('https://web.whatsapp.com/')
- print("Loading..\n")
- for x in range(5,0,-1):
- print("\b")
- print(x)
- time.sleep(1)
- def check_exists_by_xpath():
- try:
- browser.find_element_by_xpath('//span[@class="O90ur _3FXB1"]')
- except NoSuchElementException:
- return False
- return True
- count = 1
- for iterator in browser.find_elements_by_xpath('//div[@class="_2wP_Y"]'):
- iterator.click()
- cellA = "A" + str(count)
- cellB = "B" + str(count)
- time.sleep(2)
- name = browser.find_element_by_xpath('//div[@class="_3XrHh"]/span').text
- if check_exists_by_xpath() == True:
- sheet[cellA] = name
- sheet[cellB] = " isOnline\n"
- sheet[cellA].fill = PatternFill(start_color="a4d968", end_color="a4d968", fill_type = "solid")
- sheet[cellB].fill = PatternFill(start_color="a4d968", end_color="a4d968", fill_type = "solid")
- if check_exists_by_xpath() == False:
- sheet[cellA] = name
- sheet[cellB] = " isOffline\n"
- count = count + 1
- workbook.save(filename="WhatsApp_Data.xlsx")
- print("Complete..!")
- browser.close()
Have Fun at Home ;)
Articoli simili
- Come scaricare Pokémon GO Guide to Pokémon GO Secrets, Tips & Tricks: Pokémon GO, Secrets, Android, iOS, Cheats, Hints, Teams, Gyms ebook gratis
- What are some options to stream Korean channels? Should I get a Roku, Amazon Fire Stick, or Apple TV? What are some of the Korean channels?
- What are some cool Python programs that require less than 50 lines of code?
- È consigliabile imparare Tkinter in Python per avanzare la propria carriera o per ottenere una migliore offerta di lavoro come sviluppatore Python?
- Come eseguire uno script Python senza installare Python