我正在尝试使用Google Play抓取工具,并且需要使用NodeJS编写的所有appId的完整列表。我的问题是它仅提供console.log的输出。我需要将其保存为JSON,然后转换为CSV。您知道如何将其保存到JSON吗?我是NodeJS的新手。
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!');
});
答案 0 :(得分:0)
// 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);