Advertisement
JackGrimm

Untitled

Jan 14th, 2022
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. from selenium import webdriver
  2. from selenium.webdriver.chrome.options import Options
  3. from selenium.webdriver.support.ui import WebDriverWait
  4. from selenium.webdriver.common.keys import Keys
  5. from selenium.webdriver.common.action_chains import ActionChains
  6. import time
  7.  
  8. chromepath = "C:\Python36\chromedriver_win32\chromedriver.exe" # Selenium chromedriver path
  9. options = webdriver.ChromeOptions()
  10. options.add_argument("user-data-dir=C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\User Data")
  11. #Above is used to keep whatsapp logged in.
  12. #options.add_argument("--headless") doesn't working with whatsapp
  13.  
  14.  
  15. def SendMessage (message, namelist):
  16. driver = webdriver.Chrome(executable_path=chromepath, chrome_options=options)
  17. driver.get("https://web.whatsapp.com/")
  18.  
  19. while True:
  20. try:
  21. appLoad = driver.find_element_by_class_name("_1lPgH") #Any class that exists after login. Whatsapp keeps updating this
  22. if appLoad:
  23. print("found :D")
  24. break #The login was successful
  25. except:
  26. print("reload")
  27. time.sleep(2) #Wait for the page to load and retry
  28.  
  29. for name in namelist:
  30. try: #Note: Whatsapp updates the xpaths every now and then
  31. input_box_search = driver.find_element_by_xpath('/html/body/div[1]/div/div/div[3]/div/div[1]/div/label/div/div[2]')
  32. input_box_search.click()
  33. input_box_search.send_keys(name, Keys.ENTER)
  34. user = driver.find_element_by_xpath(f"//span[@title='{name}']")
  35. user.click()
  36. for x in range(500):
  37. text_box = driver.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[1]/div/div[2]')
  38. text_box.send_keys(message,Keys.ENTER)
  39. print(x)
  40. except:
  41. print("error")
  42. driver.close()
  43. time.sleep(1) #some messages aren't sent fast enough
  44. driver.close()
  45. print("Completed")
  46.  
  47.  
  48. if __name__ == "__main__":
  49. SendMessage("Unsubscribe!", ["Spam Project"])
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement