Skip to content

Instantly share code, notes, and snippets.

@ljaviertovar
Last active July 25, 2021 14:51
Show Gist options
  • Save ljaviertovar/792fb886b2504db5780b5bda8ca12963 to your computer and use it in GitHub Desktop.
Save ljaviertovar/792fb886b2504db5780b5bda8ca12963 to your computer and use it in GitHub Desktop.
Scraper to get songs of spotify and create playlist on youtube
// go to the playlists section
const [linkPlaylist] = await page.$x("//a[contains(text(), 'Playlist')]");
await linkPlaylist.click();
await page.waitForNavigation();
// get all playlists found
const listPlaylists = await page.evaluate(() => {
let list = [];
let playlists = Array.from(
document.querySelectorAll("._3802c04052af0bb5d03956299250789e-scss")
);
playlists.map((playlist) => {
let linkPlayList = playlist.querySelector("a");
list.push({
title: linkPlayList.getAttribute("title"),
link: linkPlayList.getAttribute("href"),
});
});
return list;
});
// go to first playlist
await page.goto(SP_BASE_URL + listPlaylists[0].link, { waitUntil: "networkidle2" });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment