Created
May 31, 2017 15:30
-
-
Save tzi/c3d78d93859c1c6592a6e9decec2b802 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
import fetch from 'node-fetch'; | |
import cheerio from 'cheerio'; | |
function parseHtml(url, callback) { | |
fetch(url) | |
.then(response => response.text()) | |
.then(html => cheerio.load(html)) | |
.then(callback) | |
.catch(console.error) | |
; | |
} | |
// Main | |
if (process.argv.length !== 3) { | |
console.log('Usage: npm run start http://example.com'); | |
process.exit(); | |
} | |
parseHtml(process.argv[2], $ => { | |
const srcList = []; | |
$('img').each((i, element) => { | |
srcList.push(img.src); | |
}); | |
console.dir(srcList); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment