Javascript 如何在nodejsgoogleplay中保存到JSON文件?
我正在尝试与谷歌播放刮刀,我需要一个完整的列表,所有的应用程序ID与NodeJS编写。我的问题是它只提供console.log的输出。我需要的是将其保存为JSON,然后转换为CSV。您知道如何将其保存到JSON吗?我对NodeJS是新手Javascript 如何在nodejsgoogleplay中保存到JSON文件?,javascript,node.js,web-scraping,google-play,Javascript,Node.js,Web Scraping,Google Play,我正在尝试与谷歌播放刮刀,我需要一个完整的列表,所有的应用程序ID与NodeJS编写。我的问题是它只提供console.log的输出。我需要的是将其保存为JSON,然后转换为CSV。您知道如何将其保存到JSON吗?我对NodeJS是新手 var gplay = require('google-play-scraper'); var fs = require('fs'); gplay.list({ category: gplay.category.GAME
var gplay = require('google-play-scraper');
var fs = require('fs');
gplay.list({
category: gplay.category.GAME_ACTION,
collection: gplay.collection.TOP_FREE,
num: 2
})
.then(function(apps){
fs.writeFileSync('myjsonfile.json', console.log);
})
.catch(function(e){
console.log('There was an error fetching the list!');
});
.then(function(apps){fs.writeFileSync('myjsonfile.json',json.stringify(apps));})
请为您的答案提供一些上下文,不要只是发布代码。
// Import file system module
const fs = require('fs');
const writeToFile = (fileName) => (data) => {
fs.writeFile(fileName, JSON.stringify(data), 'utf8', function(err) {
if (err) throw err;
console.log('complete');
}
);
}
gplay.list({
category: gplay.category.GAME_ACTION,
collection: gplay.collection.TOP_FREE,
num: 2
})
.then(writeToFile('your-file-name.json'), console.error);