0

let's see this one now! I have one code placing a string into input type then clicking on submit. I need to read one excel to get the string then place on that input. The problem is I'm getting error because I can't use await.page inside the excel function.

So that's my code:

const puppeteer = require('puppeteer');
const delay = require ("delay");

var Excel = require('exceljs');

var wb = new Excel.Workbook();
var path = require('path');
var filePath = path.resolve(__dirname,'sample.xlsx');

wb.xlsx.readFile(filePath).then(function(){

    var sh = wb.getWorksheet("Sheet1");

    for (i = 1; i <= sh.rowCount; i++) {
        (async () => {
            const browser = await puppeteer.launch({headless: false});
            const page = await browser.newPage();
          await page.goto('https://www.melissa.com/user/signin.aspx?src=https://www.melissa.com/v2/lookups/emailcheck/email/');
          //authentication
          await page.waitFor('input[name="ctl00$ContentPlaceHolder1$Signin1$txtEmail"]');
          await page.$eval('input[name="ctl00$ContentPlaceHolder1$Signin1$txtEmail"]', elu => elu.value = '4n1kl4t0r@gmail.com');
          await page.waitFor('input[name="ctl00$ContentPlaceHolder1$Signin1$txtPassword"]');
          await page.$eval('input[name="ctl00$ContentPlaceHolder1$Signin1$txtPassword"]', elp => elp.value = 'v3r1fy>>2020');
          await page.click('input[type="submit"]');

          //search
          var result_cell = sh.getRow(i).getCell(2).value;

          await page.waitFor('input[name="email"]');
          await page.$eval('input[name="email"]', el_e => el_e.value = result_cell);
          await page.click('input[type="submit"]');
          //await page.waitForNavigation();
          await delay(3000);
          //scrapping score
          const result_score = await page.evaluate(() => {
          let score = document.querySelector('#tableInfo50 > tbody > tr:nth-child(3) > td.text-left.bold-text').innerText
          return {
          score
          }
          })

         console.log(result_score)

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

1 Answers1

0

To read xls I did with 'xlsx' library.

XLSX = require('xlsx')

const parser = (filname, companyId, plantId) => {
  var workbook = XLSX.readFile(filname)
  var first_sheet_name = workbook.SheetNames[0]

  /* Get worksheet */
  var worksheet = workbook.Sheets[first_sheet_name]

  let revision = worksheet['H9'].v
  let om = worksheet['D10'].v
  let date_number = worksheet['D11'].v
  let tag = worksheet['G14'].v
} 

I think with this libray it will work.

For more documentation click here

  • Hi @Martin , I think its not the point what we are talking now. See all the comment – i-Guru May 07 '20 at 20:58
  • Hey @Martin. Thanks for support, but I can read the xlsx. The point here is how to execute one async task after each row. –  May 08 '20 at 15:36