Monday, 23 March 2020

Help with export to csv

Hi,​so i got an issue when i export to csv,​what is want is thisnamenumberobject1object2​but what i get isname, nummerobject1, object2object1b, object2betchere is my codeconst puppeteer = require('puppeteer');const fs = require('fs-extra');const utf8 = require('utf8');(async function scrape () {const browser = await puppeteer.launch({headless:false});const page = await browser.newPage();const url = 'examplesite.com';await page.goto(url);await fs.writeFile('out.csv', 'name, orgnummer\n', 'utf8');for( let i=0; i<5; i++){await page.waitForSelector('div.listing');const bolag = await page.$$('div.listing');for (const title of bolag){const nummer = await title.$eval('div.org-number', o =>o.innerText);const name = await title.$eval('a', h3=>h3.innerText);console.log (nummer, name);await fs.appendFile('out.csv', `${nummer}\t,${name}\n`, `utf8`,function(err) { if (err) throw err;// if no error                });            };await page.click('a.ssproff-right',{waitUntil: 'networkidle0'});await page.waitFor(500);    }console.log("done");})();

Submitted March 23, 2020 at 01:19PM by isskor

No comments:

Post a Comment