如何在NodeJS Google Play抓取工具中保存到JSON文件?

我正在尝试使用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!');
      });
lokeven 回答:如何在NodeJS Google Play抓取工具中保存到JSON文件?

// 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);
本文链接:https://www.f2er.com/3098089.html

大家都在问