Skip to content

Instantly share code, notes, and snippets.

@myakura
Created September 20, 2015 10:10
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 myakura/9b2d2dbd359d353ce7b0 to your computer and use it in GitHub Desktop.
Save myakura/9b2d2dbd359d353ce7b0 to your computer and use it in GitHub Desktop.
fetch HTML and return list of images along with their text alternatives.
// 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