In these articles we are going to see how to develope our Whatsapp Online Tracker, a simple application written in Python for getting an alert everytime a Whatsapp contact is online.
In the first part we present a possible approach in order to solve the problem and how to install everything needed for getting the job done!
In the second part we focus on how put the ingredients together and realize a simple tracker.
Whatsapp Online Tracker Course
You’ll learn to:
- Program in Python with a pratical approach.
- Use Selenium for automating web applications.
- Use XPath to select a specific node in a web page.
- Build your Telegram bot and program it by using Telepot library (send/receive messages and and pictures, filter users, react to specific commands, etc…).
- Write your own Python library and develop a complete Whatsapp API for your applications.
- Build step by step a Whatsapp Online Tracker application which can run on different systems.
- Send notification when somebody accesses Whatsapp.
- Install everything on a Raspberry Pi.
- …
Whatsapp Web
Well, as introduced our goal is to gather information about a Whatsapp contact in order to be notified when he/she opens and checks his/her messages.
In order to do that we have to find a tool that allows us to automate those actions so that we can replicate them within an application.
Whatsapp Web is what we need, infact it is an interface for interacting with our chats using any PC.
Let’s open the Whatsapp Web page and let’s pair our smartphone via the QRCode shown on the page.
If don’t know how to use Whatsapp Web, please look at this simple guide.
Once you have done, we have access to the main interface which is something like that:
Let’s say we’d like to check the status of a specific user, what we have to do is to open a New chat using the button shown in red:
now we have to insert either the phone number or the name of the contact we want to interact with and click on the first element that appears under the textbox:
doing that we are able to open a chat with the contact and visualize its current state:
Well, we have found a sequence of steps which allows to verify the online status of any contact!
Now we need to find a way to automate those steps!
Selenium for Python
We already met Selenium and we discussed on how to install it on Raspberry Pi.
We probably know that this is a framework used for testing Web application but can be used for a lot more, even for our tracker!
Intalling Selenium for Python is simple thanks to the pip installer.
I consider that you have already installed Python on your PC.
If this is not your case, please follow this guide valid for Windows, Linux and MacOS!
Let’s open our prompt and, using admin privileges, launch:
This way we update our pip installer and we install the last Selenium version.
Installing WebDriver
In order to let Selenium working properly we must install a driver compatible with our browser.
Let’s open this page and below the Drivers section let’s choose the link corresponding to the browser installed in our system.
As you would have noticed, there exits different versions for each browser.
Before we proceed, we must be sure to download the correct WebDriver, otherwise Selenium won’t work.
In order to do that, visit this page in which you can easily visualize the version of the browser used.
Once downloaded, unzip the content in a folder of your choice.
Hello World!
Now we have all the ingredients for developing our application.
Firstly, let’s verify to have everything well configured.
Using our IDE, let’s create a Python script which imports Selenium and creates an object called browser pointing to the WebDriver recently downloaded.
The script terminates opening a browser windows and loading the Google homepage.
Here the code discussed:
Let’s save the script, calling it test.py.
Now, open a prompt from the same folder in which we saved the script and execute the following command:
You should now see a browser window opening and loading the Google homepage.
XPath Selectors
Ok, now we are ready to interact with our browser.
We need just to solve another issue: how to simulate clicks and keyboard typing on the elements of a web page?
Since Selenium works with Web app, it allows to refer to an element on the page through its XPath selector: I would say that it is perfect for what we need!
As already discussed in this article, XPath allows to localize a specific item on a page.
Starting from the Whatsapp Web page, using ChroPath a tool already seen in this article, we collect the absolut paths for any element we need.
At the time of writing:
Conclusions
Perfect, at this point we have everything we need to be able to develop our Whatsapp Online Tracker.
We have understood that to monitor a contact is necessary to have an active Whatsapp account and, using the Web service, it is possible to view the current status of any user simply by searching for it and opening a chat.
We also saw that with Selenium and XPath it is possible to automate all these operations through a Python script.
In the next article we will see how to put all those ingredients together in order to achive the desidered results!
I need to ask you a question that in your Udemy course, do we have to keep our system on track numbers or can you explain the working how it is going to work.
Thanks in advance!!!!
Hi Harsh and thanks for your comment.
Please, may I ask you to explain me better what you need? I don’t understand your question… I’ll glad to help you.
Have a nice continuation,
Macheronte
Now this method is working?
Yes, it is.