Skip to content

Instantly share code, notes, and snippets.

@tzi
Created May 31, 2017
Embed
What would you like to do?
#!/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