jeudi 27 décembre 2018

How do I implement my Node.js code to work on a website?

I have a node.js code that runs perfectly in terminal. How can I display the console.log section on localhost (then Heroku)?

I'm still beginner so express is difficult for me. Should I use that? I tried Browserify too.

const puppeteer = require('puppeteer');
    (async () => {
      const browser = await puppeteer.launch();
      const page = await browser.newPage();
      var url = "URL";
      await page.goto(url);

      const eladok = await page.evaluate(() => 
      Array.from(document.querySelectorAll('div.shopname.fjump'))
        .map((eladok) => eladok.innerText.trim()));

      const hanyadik = await page.evaluate(() => 
      Array.from(document.querySelectorAll('div.shopname.fjump'))
        .map((hanyadik) => hanyadik.innerText.trim()));

      console.log('Összes ajánlat száma: ' + eladok.length);
      console.log('Helyezés: ');
      console.log(hanyadik.indexOf("usanotebook.hu") + 1);

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

I want to make a website that prompt the user for an URL then I store it to the "url" variable. The result is written below the text input.




Aucun commentaire:

Enregistrer un commentaire