从 JS 对象中提取特定字段
Extract a particular field from a JS Object
我正在使用 npm app-store-scraper 包从 App Store 获取 1000 个应用程序的应用程序 ID。使用这个 npm 包,我能够生成一个 JS 对象列表,并从 each 对象中,我的目标是获取 "id" 字段 并将其存储在 .csv 文件中。我怎样才能做到这一点?
下面是我正在使用的代码。
var store = require('app-store-scraper');
store.list({
collection: store.collection.TOP_FREE_IPAD,
category: store.category.GAMES_ACTION,
num: 1000
})
.then(console.log)
.catch(console.log);
这是我得到的响应片段(一组对象):
[{
id: '1480616990',
appId: 'com.riotgames.league.wildrift',
title: 'League of Legends: Wild Rift',
icon: 'https://is5-ssl.mzstatic.com/image/thumb/Purple124/v4/32/ce/6f/32ce6f32-282d-c935-3e2a-93aca8db4b9a/AppIcon-0-0-1x_U007emarketing-0-0-0-7-0-0-sRGB-0-0-0-GLES2_U002c0-512MB-85-220-0-0.png/100x100bb.png',
url: 'https://apps.apple.com/us/app/league-of-legends-wild-rift/id1480616990?uo=2',
price: 0,
currency: 'USD',
free: true,
description: 'Dive into Wild Rift: the skills-and-strategy 5v5 MOBA experience of League of Legends by Riot Games, now built from the ground up for mobile. With smooth controls and fast-paced games, you can team up with friends, lock in your champion, and go for the big plays.\n' +
'\n' +
'PLAY TO OUTPLAY\n' +
'Master the Rift and earn your legend with dynamic champs and ever-changing strats. Each game is a chance to land the perfect skill shot, turn the tides in a crazy teamfight, or pull off that sweet, sweet pentakill.\n' +
'\n' +
'COMPETE WITH FRIENDS\n' +
'Teamwork makes the dream work in this mobile MOBA. Whether you’re a duo, trio, or full five-stack, you can queue up with your squad and climb the ladder one enemy Nexus at a time. \n' +
'\n' +
'CHOOSE YOUR CHAMPION\n' +
'Dunk on the competition with a giant sword, freeze enemies in their tracks with a cross-the-map ice arrow, or lure opponents to their doom with mesmerizing charm. Whatever you want your legend to be, there’s a champ for you.\n' +
'\n' +
'FAIR AND FREE TO PLAY\n' +
'Face off in matches balanced for skill level as well as party size. All champions can be earned for free in Wild Rift, and there’s no paying for playtime or power. Ever.\n' +
'\n' +
'\n' +
'Follow for 200IQ gameplay clips, dev and feature updates, and a whole lot more:\n' +
'Instagram: https://instagram.com/playwildrift\n' +
'Facebook: https://facebook.com/playwildrift\n' +
'Twitter: https://twitter.com/wildrift\n' +
'Website: https://wildrift.leagueoflegends.com\n' +
'\n' +
'\n' +
'Support: https://support-wildrift.riotgames.com/\n' +
'\n' +
'Requires iOS 10.0 or later. Compatible with iPhone 6 and above.',
developer: 'Riot Games',
developerUrl: 'https://apps.apple.com/us/developer/riot-games/id346988044?uo=2',
developerId: '346988044?uo=2',
genre: 'Games',
genreId: '6014',
released: '2021-03-28T00:00:00-07:00'
},
{
id: '1550945606',
appId: 'soccer.score.star',
title: 'Soccer Super Star',
icon: 'https://is5-ssl.mzstatic.com/image/thumb/Purple124/v4/ee/2e/66/ee2e6609-651e-28f3-d7ca-a156cdb193e5/AppIcon-0-0-1x_U007emarketing-0-0-0-9-0-0-sRGB-0-0-0-GLES2_U002c0-512MB-85-220-0-0.png/100x100bb.png',
url: 'https://apps.apple.com/us/app/soccer-super-star/id1550945606?uo=2',
price: 0,
currency: 'USD',
free: true,
description: 'Become a Soccer Superstar while you score your way to the top!\n' +
'\n' +
'Play the brand new football game Soccer Super Star and enjoy the insanely real, ultra-fast and immersive football experience! \n' +
'\n' +
'Love action arcade soccer but lack the time to practice? The new Soccer Super Star’s very easy to learn game controls allows you to jump-start the fun. Just flick your finger across the screen to kick the ball and score a goal! \n' +
'\n' +
'Sounds easy, right? Wrong. As you progress through the game, shots become more challenging and you’ll need a solid strategy to bend shots and split defenses. Soccer Super Star doesn’t get overly complicated but maintains a steady increase in difficulty while offering the best flick to kick experience! Be the hero in every match. \n' +
'\n' +
'Soccer Super Star’s gameplay concept is expertly done, the high degree of independence allows you to reflect your personal strategy in the game as you level up through your dream Leagues. Dynamic levels in addition to beautifully done artwork that will top-off your truly immersive (soccer) football experience.\n' +
'\n' +
'Download to play today and score big! Yes, you can even play offline.\n' +
'\n' +
'GAME FEATURES:\n' +
'\n' +
'• PLAY OFFLINE - FREE\n' +
'It’s true, you can play and manage your team of eleven without the internet!\n' +
'\n' +
'• STAR SOCCER PLAYERS TO UNLOCK\n' +
'Utilizing the latest 2021 motion capture technology of real star players\n' +
'\n' +
'• IMMERSIVE 3D MOBILE ENGINE & ADVANCED GAME A.I.\n' +
'Intelligent game A.I. allows realistic freedom, powerful simulation with accurate ball physics. Make your way through the Leagues to be a Soccer Superstar!\n' +
'\n' +
'• JOIN WEEKLY OFFLINE TOURNAMENTS\n' +
'Be the hero for your country & Club and head for glory!\n' +
'\n' +
'• SUPER SIMPLE GAME CONTROLS\n' +
'Intuitive flick to pass and kick gameplay, sweep your finger across the ball to drive, curve and power the ball past walls of defenders.\n' +
'\n' +
'We love to hear from you! Please email us with your thoughts to soccersuperstarteam@gmail.com',
developer: 'Real Free Soccer',
developerUrl: 'https://apps.apple.com/us/developer/real-free-soccer/id1550945608?uo=2',
developerId: '1550945608?uo=2',
genre: 'Games',
genreId: '6014',
released: '2021-03-25T00:00:00-07:00'
}
]
您可以 map
遍历对象数组并仅提取每个对象的 ID。
var store = require('app-store-scraper');
store.list({
collection: store.collection.TOP_FREE_IPAD,
category: store.category.GAMES_ACTION,
num: 1000
})
.then((data) => console.log(data.map(d => d.id))
.catch((e) => console.log(e));
我正在使用 npm app-store-scraper 包从 App Store 获取 1000 个应用程序的应用程序 ID。使用这个 npm 包,我能够生成一个 JS 对象列表,并从 each 对象中,我的目标是获取 "id" 字段 并将其存储在 .csv 文件中。我怎样才能做到这一点?
下面是我正在使用的代码。
var store = require('app-store-scraper');
store.list({
collection: store.collection.TOP_FREE_IPAD,
category: store.category.GAMES_ACTION,
num: 1000
})
.then(console.log)
.catch(console.log);
这是我得到的响应片段(一组对象):
[{
id: '1480616990',
appId: 'com.riotgames.league.wildrift',
title: 'League of Legends: Wild Rift',
icon: 'https://is5-ssl.mzstatic.com/image/thumb/Purple124/v4/32/ce/6f/32ce6f32-282d-c935-3e2a-93aca8db4b9a/AppIcon-0-0-1x_U007emarketing-0-0-0-7-0-0-sRGB-0-0-0-GLES2_U002c0-512MB-85-220-0-0.png/100x100bb.png',
url: 'https://apps.apple.com/us/app/league-of-legends-wild-rift/id1480616990?uo=2',
price: 0,
currency: 'USD',
free: true,
description: 'Dive into Wild Rift: the skills-and-strategy 5v5 MOBA experience of League of Legends by Riot Games, now built from the ground up for mobile. With smooth controls and fast-paced games, you can team up with friends, lock in your champion, and go for the big plays.\n' +
'\n' +
'PLAY TO OUTPLAY\n' +
'Master the Rift and earn your legend with dynamic champs and ever-changing strats. Each game is a chance to land the perfect skill shot, turn the tides in a crazy teamfight, or pull off that sweet, sweet pentakill.\n' +
'\n' +
'COMPETE WITH FRIENDS\n' +
'Teamwork makes the dream work in this mobile MOBA. Whether you’re a duo, trio, or full five-stack, you can queue up with your squad and climb the ladder one enemy Nexus at a time. \n' +
'\n' +
'CHOOSE YOUR CHAMPION\n' +
'Dunk on the competition with a giant sword, freeze enemies in their tracks with a cross-the-map ice arrow, or lure opponents to their doom with mesmerizing charm. Whatever you want your legend to be, there’s a champ for you.\n' +
'\n' +
'FAIR AND FREE TO PLAY\n' +
'Face off in matches balanced for skill level as well as party size. All champions can be earned for free in Wild Rift, and there’s no paying for playtime or power. Ever.\n' +
'\n' +
'\n' +
'Follow for 200IQ gameplay clips, dev and feature updates, and a whole lot more:\n' +
'Instagram: https://instagram.com/playwildrift\n' +
'Facebook: https://facebook.com/playwildrift\n' +
'Twitter: https://twitter.com/wildrift\n' +
'Website: https://wildrift.leagueoflegends.com\n' +
'\n' +
'\n' +
'Support: https://support-wildrift.riotgames.com/\n' +
'\n' +
'Requires iOS 10.0 or later. Compatible with iPhone 6 and above.',
developer: 'Riot Games',
developerUrl: 'https://apps.apple.com/us/developer/riot-games/id346988044?uo=2',
developerId: '346988044?uo=2',
genre: 'Games',
genreId: '6014',
released: '2021-03-28T00:00:00-07:00'
},
{
id: '1550945606',
appId: 'soccer.score.star',
title: 'Soccer Super Star',
icon: 'https://is5-ssl.mzstatic.com/image/thumb/Purple124/v4/ee/2e/66/ee2e6609-651e-28f3-d7ca-a156cdb193e5/AppIcon-0-0-1x_U007emarketing-0-0-0-9-0-0-sRGB-0-0-0-GLES2_U002c0-512MB-85-220-0-0.png/100x100bb.png',
url: 'https://apps.apple.com/us/app/soccer-super-star/id1550945606?uo=2',
price: 0,
currency: 'USD',
free: true,
description: 'Become a Soccer Superstar while you score your way to the top!\n' +
'\n' +
'Play the brand new football game Soccer Super Star and enjoy the insanely real, ultra-fast and immersive football experience! \n' +
'\n' +
'Love action arcade soccer but lack the time to practice? The new Soccer Super Star’s very easy to learn game controls allows you to jump-start the fun. Just flick your finger across the screen to kick the ball and score a goal! \n' +
'\n' +
'Sounds easy, right? Wrong. As you progress through the game, shots become more challenging and you’ll need a solid strategy to bend shots and split defenses. Soccer Super Star doesn’t get overly complicated but maintains a steady increase in difficulty while offering the best flick to kick experience! Be the hero in every match. \n' +
'\n' +
'Soccer Super Star’s gameplay concept is expertly done, the high degree of independence allows you to reflect your personal strategy in the game as you level up through your dream Leagues. Dynamic levels in addition to beautifully done artwork that will top-off your truly immersive (soccer) football experience.\n' +
'\n' +
'Download to play today and score big! Yes, you can even play offline.\n' +
'\n' +
'GAME FEATURES:\n' +
'\n' +
'• PLAY OFFLINE - FREE\n' +
'It’s true, you can play and manage your team of eleven without the internet!\n' +
'\n' +
'• STAR SOCCER PLAYERS TO UNLOCK\n' +
'Utilizing the latest 2021 motion capture technology of real star players\n' +
'\n' +
'• IMMERSIVE 3D MOBILE ENGINE & ADVANCED GAME A.I.\n' +
'Intelligent game A.I. allows realistic freedom, powerful simulation with accurate ball physics. Make your way through the Leagues to be a Soccer Superstar!\n' +
'\n' +
'• JOIN WEEKLY OFFLINE TOURNAMENTS\n' +
'Be the hero for your country & Club and head for glory!\n' +
'\n' +
'• SUPER SIMPLE GAME CONTROLS\n' +
'Intuitive flick to pass and kick gameplay, sweep your finger across the ball to drive, curve and power the ball past walls of defenders.\n' +
'\n' +
'We love to hear from you! Please email us with your thoughts to soccersuperstarteam@gmail.com',
developer: 'Real Free Soccer',
developerUrl: 'https://apps.apple.com/us/developer/real-free-soccer/id1550945608?uo=2',
developerId: '1550945608?uo=2',
genre: 'Games',
genreId: '6014',
released: '2021-03-25T00:00:00-07:00'
}
]
您可以 map
遍历对象数组并仅提取每个对象的 ID。
var store = require('app-store-scraper');
store.list({
collection: store.collection.TOP_FREE_IPAD,
category: store.category.GAMES_ACTION,
num: 1000
})
.then((data) => console.log(data.map(d => d.id))
.catch((e) => console.log(e));