Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from selenium import webdriver
- from selenium.webdriver.chrome.options import Options
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.common.keys import Keys
- from selenium.webdriver.common.action_chains import ActionChains
- import time
- chromepath = "C:\Python36\chromedriver_win32\chromedriver.exe" # Selenium chromedriver path
- options = webdriver.ChromeOptions()
- options.add_argument("user-data-dir=C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\User Data")
- #Above is used to keep whatsapp logged in.
- #options.add_argument("--headless") doesn't working with whatsapp
- def SendMessage (message, namelist):
- driver = webdriver.Chrome(executable_path=chromepath, chrome_options=options)
- driver.get("https://web.whatsapp.com/")
- while True:
- try:
- appLoad = driver.find_element_by_class_name("_1lPgH") #Any class that exists after login. Whatsapp keeps updating this
- if appLoad:
- print("found :D")
- break #The login was successful
- except:
- print("reload")
- time.sleep(2) #Wait for the page to load and retry
- for name in namelist:
- try: #Note: Whatsapp updates the xpaths every now and then
- input_box_search = driver.find_element_by_xpath('/html/body/div[1]/div/div/div[3]/div/div[1]/div/label/div/div[2]')
- input_box_search.click()
- input_box_search.send_keys(name, Keys.ENTER)
- user = driver.find_element_by_xpath(f"//span[@title='{name}']")
- user.click()
- for x in range(500):
- text_box = driver.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[1]/div/div[2]')
- text_box.send_keys(message,Keys.ENTER)
- print(x)
- except:
- print("error")
- driver.close()
- time.sleep(1) #some messages aren't sent fast enough
- driver.close()
- print("Completed")
- if __name__ == "__main__":
- SendMessage("Unsubscribe!", ["Spam Project"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement