A Beginner’s Guide to Bot Creation and Automation

Tanmayee Choudhury
May 8 · 5 min read

Every job has repetitive tasks and processes that can be automated, which can take up a significant amount of your time. In a digital world, automation is the most crucial skill to acquire. In this article, I’ll be guiding you through the basic techniques used in order to create bots for diverse applications. Together we will create simple bots to search in Google and automatically like random posts on Instagram. So, without any further adieu let’s dive in!

Google Search Bot

Firstly, we would be building a simple Search bot that automatically opens up a web browser, loads the Google page and types a term to be searched. Once the next page loads, it takes a screenshot and clicks on Images which then redirects it to images of the term searched. It takes another screenshot of the new page and clicks on the first image it finds. It takes the final screenshot and closes the browser. Interesting isn’t it?

Create a folder named GoogleSearchBot. Open that folder in VSCode and create a file named simple.js. Now, install a new Nodejs project with node init -y and then install the playwright library with npm i playwright. For those of you who are curious to know what this playwright library is and what does it do, playwright is basically a Node.js library to automate Chromium, Firefox and WebKit with a single API. It is built to enable cross-browser web automation that is ever-green, capable, reliable and fast. You can find more about Playwright at https://github.com/microsoft/playwright. Some of the alternatives are Puppeteer or Selenium.

For the async/await feature to operate properly, you need to have a minimum version of 8 for Nodejs. Before getting started with automation and bot creation, you are expected to have some basic knowledge of Chrome DevTools provided by Google Chrome. It would make the tasks a lot easier. When you load a webpage, right click and select Inspect option, the DevTools window appears. The section of the webpage which you want to automate, always has a unique element. You need to look for that unique element. It can be done by opening DevTools and selecting the section of the page you want to automate which would then highlight the respective HTML code under the Elements tab of the Inspect window. You need to find the unique element in that part of the code.

The code for simple.js is as follows:

Let’s run the code by typing node simple.js. Once your code starts running, the Search bot gets activated and starts doing all the tasks provided in the code. The screenshots which it takes are automatically stored in your GoogleSearchBot folder (focus on the left side of the VSCode in the video below, before the bot starts and after the bot completes its task). Let’s have a look at its functionality:

Instagram Like Bot

Now that we gathered a basic knowledge of bot creation, it’s time to advance up a bit. So, we would be designing an Instagram Like Bot that automatically logs in to your Instagram account via your email and password and randomly likes the posts and comments that appear on your feed.

By now, you all must be knowing the starter pack for any Nodejs project: Create a folder named InstaLikeBot → Open VSCode → Open the InstaLikeBot folder → Create a file named instagram.js → Open the terminal window and type npm init -y → Install the playwright library and dotenv package by typing npm install dotenv playwright → Get started with the code.

Here, we would be making use of Environment Variables. So, install the dotenv package to create a virtual environment for your project by typing npm install dotenv. Now, create a file named .env to store the confidential information such as username, email, password, etc. The code for instagram.js looks something like this:

And we’re done! Now let’s run the project by typing node instagram.js . The bot gets activated and starts working as shown below:

So, that’s all from my side. I hope you will enjoy creating the bots and use your time efficiently and productively. The functionality of the bots are kept pretty simple for easy understanding. You can always add in additional and interesting features to the bots. Moreover, you can now try to create Spotify Listener Bot, Telegram Bot or Twitter Follower Bot. Thanks for reading. Have a good day!

From Confusion to Clarification

Nerd For Tech
Tanmayee Choudhury

Written by

Btech Undergrad at VIT, Vellore. Budding Web Developer, keen learner, optimist.

Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/. Don’t forget to check out Ask-NFT, a mentorship ecosystem we’ve started

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

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