Created
September 20, 2015 10:10
-
-
Save myakura/9b2d2dbd359d353ce7b0 to your computer and use it in GitHub Desktop.
fetch HTML and return list of images along with their text alternatives.
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
// haven't tested yet | |
const jsdom = require('jsdom') | |
const url = process.argv[2] | |
jsdom.env(url, (err, window) => { | |
const images = Array.from(window.document.querySelectorAll('img[src]')) | |
const result = [] | |
for (let i of images) { | |
result.push({ | |
src: i.src, | |
alt: i.hasAttribute('alt') ? i.alt : null | |
}) | |
} | |
console.log(JSON.stringify(result, null, 2)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment