Anyone who has ever had to send a direct message on Instagram through their website knows how uninspiring the task is. This script automates the entire process and messages the person of your choice given that he/she is in your follow list and vice versa.
This project was made entirely using Selenium, a python module that helps in web automation and data scraping.
The script describes the steps to follow in order to DM a person on Instagram to selenium. The steps include logging in, disabling prompts, searching for the person, opening their profile, and finally sending a message. There are two versions of this script, the first version manually pauses the program after every step before the page gets loaded while the second script uses a method called WebDriverWait that automatically halts the program until it detects the HTML element that it requires to perform the next step. Using WebDriverWait reduces the execution time from ~50 seconds to ~22 seconds, thus, increasing the speed by over 200%.
Here's a gif of what the script does:
- The script executes on Firefox so the Geckodriver.exe is used. To use the script on any other browser, please download the relevant drivers.
- The speed of the script depends on the speed of the Internet. If it's too slow, the program might fail.
- Not every needed element is of the same type, sometimes the script looks for XPATHS, sometimes it looks for CSS Selectors. These elements were decided after conducting vigorous trials and errors.