Skip to content

Instantly share code, notes, and snippets.

@tzi
Created May 31, 2017 15:30
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 tzi/c3d78d93859c1c6592a6e9decec2b802 to your computer and use it in GitHub Desktop.
Save tzi/c3d78d93859c1c6592a6e9decec2b802 to your computer and use it in GitHub Desktop.
#!/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