我需要一些与此代码有关的帮助,即时通讯试图抓取一个网站,然后将其转换为csv文件,我想念的是什么?这个想法是让函数循环遍历所有页面并将它们放入数组[bolag]中,然后我想将其分成csv文件中的2行
const puppeteer = require('puppeteer');
const fs =require('fs');
(async function scrape () {
const browser = await puppeteer.launch({headless:false});
const page = await browser.newPage();
const url = 'https://www.proff.se/segmentering?rf=-15600&rt=186296000&samplerFilter=true';
await page.goto(url);
for( let i=0; i<100; i++){
const titles = await page.evaluate(
() => Array.from(document.querySelectorAll("div.segmentation h3 a")).map((partner) =>
partner.innerText)
);
const OrgNumber = await page.evaluate(
() => Array.from(document.querySelectorAll("div.segmentation .org-number")).map((partner) =>
partner.innerText)
);
let Bolag = [titles, OrgNumber];
console.log(Bolag);
await page.click('a.ssproff-right');
}
fs.writeFile("test.csv",JSON.stringify(bolag), function(err){
if(err){
console.log(err);
}else{
console.log("data has been added");
}
})
})();