G
G
Goobert Crypto2020-01-01 19:45:33
Node.js
Goobert Crypto, 2020-01-01 19:45:33

How to login to instagram using Node.js with puppeteer connected?

When writing a bot, I ran into an authorization problem in instagram. I can’t figure out what I did wrong))
const puppeteer = require('puppeteer');
const sleep = (ms)=> new Promise(executor, (res)=>{
setTimeout(res,ms)
});
(async () => {
const browser = await puppeteer.launch(
{
headless: false,}
);
const page = await browser.newPage();
await page.goto(' https://www.instagram.com/accounts /login/ ');
await page.sleep(ms,5000);
await page.$eval('input[name="username"]',(username)=>
{ username.nodeValue ='test'});
await page.$eval('input[name="password"]',
{ username.nodeValue ='1234'})
await page.click('.Igw0E.IwRSH.eGOV_._4EzTm');
await page.screenshot({path: 'example.png'})
await browser.close();
})()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2020-01-01
@goober-crypto

It's simple (I just have confusion about drug addiction like page.$eval and page.click('.Igw0E.IwRSH.eGOV_._4EzTm') )

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({headless: false});
  const page = await browser.newPage();
  await page.goto('https://www.instagram.com/accounts/login/');
  await page.waitFor('input[name="username"]');
  await page.focus('input[name="username"]');
  await page.keyboard.type('login111');
  await page.focus('input[name="password"]');
  await page.keyboard.type('password');
  await page.click('button[type="submit"]');
  await new Promise(r => setTimeout(r, 5000));

  await browser.close();
})();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question