Last active
July 25, 2021 17:07
-
-
Save ljaviertovar/c4bfa11397a8c951bbcaa4c92e584b41 to your computer and use it in GitHub Desktop.
Scraper to get songs of spotify and create playlist on youtube
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
const listTracks = await page.evaluate(() => { | |
let list = []; | |
let tracks = Array.from( | |
document.querySelectorAll('div[data-testid="tracklist-row"]') | |
); | |
tracks.map((track) => { | |
let divTrack = track.querySelectorAll("div")[2]; | |
let trackData = divTrack.querySelector( | |
"div > div .da0bc4060bb1bdb4abb8e402916af32e-scss" | |
); | |
let artistData = divTrack.querySelector("div > div > span > a"); | |
// clean the strings | |
let artist = artistData.innerHTML.replace(/[^a-zA-Z ]/g, "").trim(); | |
// in my case, I want to remove "New Stereo Mix" from the string | |
let song = trackData.innerHTML.replace(/[^a-zA-Z ]/g, "").replace("New Stereo Mix", "").trim(); | |
list.push({ | |
song, | |
artist | |
}); | |
}); | |
return list; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment