0

pushing singleCompany object in company array, but after all process console.log company array it gives empty array. what is the error which is not adding singleCompany to company array.

const rp = require('request-promise');
const cheerio = require('cheerio');

let company = [];

for (var x = 50000; x < 50003; x++) {
  let url = `https://scci.com.pk/member-details/?id=A-${x}`;





    rp(url).then((html) => {
      let $ = cheerio.load(html);

      let name = $("tr:eq(1)").text().replace(/\s{2,}/g, ' ').trim();
      let email = $("label[for='cp_email']").parent().next().text();
      let ptcl = $("label[for='cp_phone']").parent().next().text();
      let mobile = $("label[for='cp_mobile']").parent().next().text();
      let singleCompany =
      {
        name: name,
        email: email,
        ptcl: ptcl,
        mobile: mobile
      }
      company.push(singleCompany);
    });

};
console.log(company)
T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
Zian Ejaz
  • 23
  • 4

0 Answers0