Skip to content

Instantly share code, notes, and snippets.

@kentcdodds
Last active July 12, 2016 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kentcdodds/8edb40cd941ee8cc04bf06312ce37ebf to your computer and use it in GitHub Desktop.
Save kentcdodds/8edb40cd941ee8cc04bf06312ce37ebf to your computer and use it in GitHub Desktop.
Get Characters from the IMDB page for a movie (i.e. http://www.imdb.com/title/tt0241527/fullcredits?ref_=tt_cl_sm#cast)
var tableRowNodes = document.querySelectorAll('.cast_list tr')
var tableRowArray = Array.from(tableRowNodes)
var {mainCast} = tableRowArray.reduce((acc, row) => {
if (!acc.firstSkipped) {
acc.firstSkipped = true
} else if (acc.restOfCastStarted) {
acc.rest.push(row)
} else if (row.classList.contains('odd') || row.classList.contains('even')) {
acc.mainCast.push(row)
} else {
acc.restOfCastStarted = true
}
return acc
}, {mainCast: [], rest: []})
var characters = mainCast
.map(node => node.querySelector('.character a'))
.filter(anchor => !!anchor)
.map(anchor => anchor.textContent)
console.log(characters)
copy(characters)
console.log('The characters have been added to your clipboard')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment