Casa > W > What Are Some Python-Whatsapp Tricks?

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:

  1. from selenium import webdriver 
  2. from selenium.webdriver.common.keys import Keys 
  3. from selenium.common.exceptions import NoSuchElementException 
  4. from openpyxl import Workbook 
  5. from openpyxl.styles import PatternFill 
  6. import time 
  7.  
  8. workbook = Workbook() 
  9. sheet = workbook.active 
  10.  
  11. browser = webdriver.Chrome(executable_path=r"F:\software\chromedriver_win32\chromedriver.exe") 
  12. //enter your driver path above 
  13. browser.get('https://web.whatsapp.com/') 
  14.  
  15. print("Loading..\n") 
  16.  
  17. for x in range(5,0,-1): 
  18. print("\b") 
  19. print(x) 
  20. time.sleep(1) 
  21.  
  22. def check_exists_by_xpath(): 
  23. try: 
  24. browser.find_element_by_xpath('//span[@class="O90ur _3FXB1"]') 
  25. except NoSuchElementException: 
  26. return False 
  27. return True 
  28.  
  29.  
  30. count = 1 
  31. for iterator in browser.find_elements_by_xpath('//div[@class="_2wP_Y"]'): 
  32. iterator.click() 
  33.  
  34. cellA = "A" + str(count) 
  35. cellB = "B" + str(count) 
  36. time.sleep(2) 
  37. name = browser.find_element_by_xpath('//div[@class="_3XrHh"]/span').text 
  38. if check_exists_by_xpath() == True: 
  39. sheet[cellA] = name 
  40. sheet[cellB] = " isOnline\n" 
  41. sheet[cellA].fill = PatternFill(start_color="a4d968", end_color="a4d968", fill_type = "solid") 
  42. sheet[cellB].fill = PatternFill(start_color="a4d968", end_color="a4d968", fill_type = "solid") 
  43. if check_exists_by_xpath() == False: 
  44. sheet[cellA] = name 
  45. sheet[cellB] = " isOffline\n" 
  46. count = count + 1 
  47.  
  48. workbook.save(filename="WhatsApp_Data.xlsx") 
  49. print("Complete..!") 
  50. browser.close() 

Have Fun at Home ;)

De Bradeord Frasch

Como enraizar o meu Straight Talk LG Treasure :: As pessoas percebem que você pode enviar maconha através de carregadores noturnos com detecção zero?