Reading the latest WhatsApp messages with python

Photo by Dima Solomin on Unsplash

Hi! I had built this some time ago this code and now I want to share it with everyone. My idea was to open WhatsApp, select the phone number, and read the messages, but then I needed to do this:

  • Open WhatsApp using WhatsApp's web protocol

In this case, the coordinates below may not be correct in your case, so remember to update them:

import pyautogui
import time

But first, you need to install the libraries:

$ pip3 install webbrowser
$ pip3 install pyautogui

And here’s the full code:

import webbrowserimport pyautoguiimport timeimport pyperclipphone = pyautogui.prompt('Telephone number')"whatsapp://send?phone=" + phone)time.sleep(10), 916)time.sleep(0.2)pyautogui.dragTo(587, 127, 0.2, button='left')pyautogui.hotkey('ctrl', 'c')ret = pyperclip.paste()pyautogui.alert(ret, "results")print("\n\n*******************\n\n" + ret + "\n\n"), 4)

Thank you for reading!



Hi! I'm Tiago, a student at Lisbon, Portugal.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store