Get Characters from the IMDB page for a movie (i.e. http://www.imdb.com/title/tt0241527/fullcredits?ref_=tt_cl_sm#cast)
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
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