我正在从木偶响应侦听器中将数百万个json对象保存到文本文件中。哪个选项具有更好的性能,并被视为最佳实践。
选项1-带有JSON.stringify
//puppeteer listener
page.on("response",async response => {
let jsonResponse = await response.json();
await fs.writeFileSync(
"1.json",JSON.stringify(jsonResponse)
);
})
选项2-将响应转换为文本
page.on("response",async response => {
let jsonTextResponse = await response.text();
await fs.writeFileSync(
"2.json",jsonTextResponse
);
})