Puppeteer take data from Submit

Asked

Viewed 238 times

1

The goal is to have a simple html with a text input and when the user gives Submit the input with the instagram username, the Puppeteer receive the url ('https://instagram.com/${username}') but I’m days trying to pass this ${username} from frontend to backend and I can’t.

HTML

<form name="" action="">
        <input type="text" name="username" id="username">
        <input type="submit" value="submit" onclick="submitName()">
</form>
<script src="./scripts/index.js"></script>

index js.

const ig = require('./instagram');
async function submitName(){
  const inputUsername = document.querySelector('#username');
  const username = await inputUsername.value
  await ig.inicialize(`https://instagram.com/${username}`)
  console.log(`https://instagram.com/${username}`);
};

instagram js.

const puppeteer = require('puppeteer');

    const instagram = {
        browser: null,
        page: null,
    
        inicialize: async (url) => {
            instagram.browser = await puppeteer.launch({headless: false});
            instagram.page = await instagram.browser.newPage();
            await instagram.page.goto(url)
    }
}
        
module.exports = instagram;

Does anyone know what I’m doing wrong? I know I have to run Node instagram.js, but there’s no way to run it without having the url, I’m already lost...

  • Look, as far as I know, to run Puppeteer you have to use Node. That way Voce who made the form I believe will not run your instagram robot. My suggestion: create a server with express and a simple route, and pass by post or get the url typed by the user. Then just pass the url to the function that runs the robot and you’re done.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.