Instagram is most widely used social media platform these days so there is a lot of useful data available in it so why not to fetch some data from Instagram and make it useful, for this we have to login first.
what is puppeteer js?
Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol.
npm init -y
now we will install our packages
npm i puppeteer
npm i express
npm i cors
lets make our App.js file in which we will make our server and then deploy it locally e.g. localhost:3000
Server is Running Successfully…
After deploying server we will make our routes file in which we will perform our express.js routing.
lets Test it first:
Server is Responding!!!
For Instagram log in first we have to set our base URL which will redirect us to login page of Instagram.
Setting base URL
Now we will create Instagram Object in which we will make properties e.g. Page, browser and initialize method which will launch puppeteer headless browser
Creating Object Called Instagram
If headless: true then you will not see any chrome browser opening if you want to see what event is triggered on chrome browser you have to make headless: false
Now we will make asynchronous login function in which we will perform all our login events.
now we will be navigating to Base URL.
Navigation to Base URL .
by doing inspect element we can get HTML of that specific element
Inspect element of Username and Password Input bar.
we use <<.page.type>> function to perform typing event on username and password bar.
After typing our username and password we have to perform click event on the log In button
Copying selector of the Log In Button
for Clicking this we have to get selector of log In button
First go to html of button by doing inspect element on it.
then left click on log In button Html then go to copy then select copy selector.
now we will perform click event.
Clicked Event performed
we used .page.click event to perform click on the button or anything else.
Lets Run now.
Log In into Instagram
So we are successfully Logged In.
if you see any other message after logging In e.g. Save info etc. just copy the selector of button and perform click event on it like we did before,
Please put await, loadDOMcontent, networkidle2 or networkidle0 These all will let the content or page load completely before triggering any event.
Waiting for navigation to perform completely.