This is fully automated version of Whatsapp on Selenium. Cause Meta wants you to pay for their own.
This is a selenium based python framework, that will allow you extract or send messages from whatsapp, which will be saved in a .CSV file. You can later run data analysis on it or train a model.
The App uses Web.Whatsapp.com to extract messages in an automated fashion. You will be provided with a QR-Code on first run to login. After that you can start extracting in Headless mode. Browser Data/Session is saved in UserData folder in same directory as your script.
- First clone the prjoect then install requirements from the
requirements.txt
pip install -r requirements.txt
-
Install Chrome web driver from here https://chromedriver.chromium.org/downloads and Chrome browser from here https://www.google.com/chrome. Make sure to add your web driver to your system path, although it is not necessary.
-
You can import the
WhatsExtract.py
into your main python file.
from Whatsapp import Whatsapp
Now you can use the object of the class to extract message. Example 1:
bot = Whatsapp(silent=True, headless=False)
bot.login()
bot.getMessages("Alex", scroll=10)
For the default constructor you have three options
executable_path
You can specifiy the path from your Chrome driver if not already in your system PATH. The Format should be likeC:/Driver/chromedriver.exe
.silent
has two optionsTrue
orFalse
. If set to True, it will not display selenium logs.headless
has two optionsTrue
orFalse
. If set to True, the browser will be headless (not visible).
Has 4 arguments
chatName
- This will be the chatname you want to extract messages from. Could be part of the chatName. It utilizes WhatsApp chat search to find the chat.all
has two optionsTrue
orFalse
. If set to True, will true to extract all available chats. Although it may stop before that, see OPTION 4.scroll
You can set to any integer for scolling some of the chat, to extract more messages.manualSync
has two optionsTrue
orFalse
. If set to True, script will wait for your input before it start extracting messages. Its so can manually scroll to where you want the messages extraction to begin from.
Has 2 arguments
element
- This is message element, you want to reply to. It is a selenium objectmsg
Its the message you want to send.
Has 2 arguments. Return last incomming message element and parsed message.
chatName
- This is chat name you want to listen to.func
This is a async function you set to do things with the message returned.
Example:
responses = {"hello": "Hello, Nice to meet you !", "How are you ?": "I'm fine, thank you !",
"Who are you ?": "My name is RevBot, I'm a chatbot made by AbdulRahman Nadeem."}
async def func(element, msg):
print(msg)
if (msg[2] == "EXIT!"):
bot.browser.close()
exit()
if (msg[2].lower() == "help"):
bot.replyTo(
element, str("My commands are : " + str(responses)))
else:
try:
bot.replyTo(element, responses[msg[2].lower()])
except:
bot.replyTo(element, "I don't understand !")
bot.hookIncomming("AbdulRahman", func)
- Sometimes the sender name will be mangled.
- Unable to diffrentiate between VoiceNote in a replied message.
- Too many workarounds done in script, which might fail.
- Add support for Emojis
- Add support to diffrentiate between different media.
- Better Sync controll, to download all messages.