Skip to content

Instantly share code, notes, and snippets.

@mike-at-redspace
Last active July 29, 2023 10:15
Show Gist options
  • Save mike-at-redspace/5aece765a9b0cca64d7c347c24b9f6af to your computer and use it in GitHub Desktop.
Save mike-at-redspace/5aece765a9b0cca64d7c347c24b9f6af to your computer and use it in GitHub Desktop.
Client-side scrape Cast from IMDB
// https://www.imdb.com/title/tt1865740/fullcredits
const collectData = () => {
try {
const data = { cast: [], crew: [] };
const fullCredits = document.getElementById('fullcredits_content');
for (const child of fullCredits.children) {
if (child.classList.contains('simpleCreditsTable')) {
for (const row of child.rows) {
const [nameCell, , creditCell] = row.cells;
const name = nameCell.querySelector('a').textContent.trim();
const credit = creditCell.textContent.trim();
data.crew.push({ name, credit });
}
} else if (child.classList.contains('cast_list')) {
const photos = document.querySelectorAll('.cast_list .primary_photo a');
const nameCells = document.querySelectorAll('.cast_list .primary_photo + td a');
const characterCells = document.querySelectorAll('.cast_list .character');
for (const [i, photo] of photos.entries()) {
const name = nameCells[i].textContent.trim();
const character = characterCells[i].textContent.trim();
data.cast.push({
name,
photo: photo.href,
character
});
}
}
}
return data;
} catch (error) {
console.error(error);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment