In the previous article we introduced the necessary tools in order to develop our Whatsapp Online Tracker.
Today we are going to see how to put all those ingredients together.
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.
Buy the course with this coupon!
Let’s start showing the working code, we are going to spend a little bit of time in order to explain the most important blocks.
Remember that in order to get the job done, you need to have a phone number with an active Whatsapp account.
Selectors and Contact List
As we have seen in the first part of this guide, XPath selectors play an important role.
Thanks to this instrument we can uniquely identify all the elements in a web page.
In our case we need to select the following components:
With the first one we obtain a link to the new chat button.
The second one offers a reference to the text area that shows up when you click to the previous button and is used for inserting the phone number you want to control.
The third one allows to get the point in which the user connection state is shown.
At the end, we define a dictionary containing the users that we want to track. The list is composed by a nickname and the phone number.
Now that we have defined the fundamental ingredients represented by the selectors and the contact list, it’s time to create an object which interacts with our browser.
With that, we can load the Whatsapp Web page and instantiate the wait object which allows to define some interesting functionalities:
In the previous code, we ask Selenium to wait for the new chat button and then we click on that button.
In order to simulate the keyboard input, we use the following instructions:
As you might have noticed, in this case we are asking Selenium to write the phone number of the contact we want to track in the text are that shows up after the previous click and, after 1 second, press ENTER.
At this point, we just have to wait for few seconds and then check that the online label is visible under the user’s name.
If so, we can infer that the contact is online, otherwise will be offline.
Need a tracker ready to be used?
Check it out!
If you’re interested in extending the functionality of your tracker to check numbers not in your address book, check out this article.
Ok, we have seen which are the main ingredients that let our tool working.
Once terminated the code analysis, just start the script.
If everything is correct, we should see a browser window loading the Whatsapp Web page.
Once paired your device using the QrCode, the main Whatsapp Web interface will be loaded and then Selenium will start to programatically check the users specified.