DEV Community

Sunil Aleti
Sunil Aleti

Posted on

How I texted whole movie script word by word using Selenium in Python πŸ˜…

GitHub logo aletisunil / Whatsapp_Spam

A python script to text the entire movie script one word at a time through whatsapp using selenium


Hey all,
Hope everyone are doing good, In this post I will share how I texted a whole movie script word by word (just to irritate her) in Python.

Let's start by watching small demo, how its going to look at end πŸ˜…

run the script

Now lets talk,
Prerequisites:

  • Python
  • Selenium
  • webdriver (I used Chrome webdriver)

Step 1 :
need to import webdriver, keys and sleep

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
Enter fullscreen mode Exit fullscreen mode

Step 2 :
Enter the location of Chrome Webdriver and assign it to driver variable

driver=webdriver.Chrome("")
Enter fullscreen mode Exit fullscreen mode

Step 3 :
I used whatsapp to send messages and I pinned the person to whom we need to send messages, so that there will not be any hustles.

driver.get("https://web.whatsapp.com/")
sleep(15)
driver.find_element_by_xpath("/html/body/div/div/div/div/div/div/div[1]/div/div/div[1]/div/div/div").click()
sleep(5)
Enter fullscreen mode Exit fullscreen mode

There should be some time where we can scan the qrcode to login, so I gave sleep(15) and that xpath is to open the chat window of that respective person

Step 4 :
Now locate the movie script file, assign it to fileLocation variable and open it in read mode
fileLocation= "" #Enter location of movie script file

Step 5 :
Now use "for loop" to send msg word by word

Code

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep


driver=webdriver.Chrome("") #Enter Location of Chrome driver
driver.maximize_window()
driver.get("https://web.whatsapp.com/")
sleep(15)
driver.find_element_by_xpath("/html/body/div/div/div/div/div/div/div[1]/div/div/div[1]/div/div/div").click()
sleep(5)
fileLocation= ""  #Enter location of movie script file
with open(fileLocation,"r") as file:
    for line in file:
        for word in line.split(" "):
            driver.find_element_by_xpath("//*/footer/div[1]/div[2]/div/div[2]").send_keys(word)
            driver.find_element_by_xpath("//*/footer/div[1]/div[2]/div/div[2]").send_keys(Keys.ENTER)
Enter fullscreen mode Exit fullscreen mode

A β™₯️ would be Awesome 😊

Top comments (5)

Collapse
 
philipperoubert profile image
Philippe Roubert

Or, how to get banned from using Whatsapp the quickest way possible πŸ˜‚
But nice one, at first I got surprised you could send messages in whatsapp through python, and then when I saw your use of selenium on the web platform, I thought "ah, of course".

Collapse
 
sunilaleti profile image
Sunil Aleti

I'm not doing this on daily basis to get banned πŸ˜… and btw I using sleep commands and u can also checkout my "Automating Instagram" post which is used to like all posts of a respective user

Collapse
 
kamo profile image
KAIDI

Nice

Collapse
 
bigaston profile image
Bigaston

It's fantastic to see how it's easy at the principle, but so smart for the realisation! GG and very nice work!

Collapse
 
sunilaleti profile image
Sunil Aleti

Thanks a lot