Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.