Skip to content

Instantly share code, notes, and snippets.

@michaelnagy
Last active June 25, 2017 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelnagy/2e46afad16ae4dc55ba0ce6f3eb644b0 to your computer and use it in GitHub Desktop.
Save michaelnagy/2e46afad16ae4dc55ba0ce6f3eb644b0 to your computer and use it in GitHub Desktop.
A simple node.js script to crawl and download information and images from pokeapi and pokemondb.net
// Nodejs > 7 or some babel is required cause we use ES7 syntax here (arrow functions and async await)
// This script requires node-fetch and image-downloader packages in order to work
// get it in npm:
// npm install --save image-downloader node-fetch
const download = require('image-downloader')
const fetch = require('node-fetch')
// We are doing a for loop to get info for the first 152 pokemons
for (var i = 1; i < 153; i++){
const asyncDownload = async () => {
try {
// download JSON information needed to crawl pokemondb
let json = await (await fetch('https://pokeapi.co/api/v2/pokemon/'+i+'/')).json()
console.log(json.name);
// download the pokemon images
let result = await download.image({url: 'https://img.pokemondb.net/artwork/'+json.name+'.jpg', dest: __dirname+'/pokemons'})
console.log('File saved to', result)
}
catch (error) {
console.log('request failed', error)
}
}
asyncDownload()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment