Skip to content

Instantly share code, notes, and snippets.

@josharagon
Last active March 21, 2024 00:17
Show Gist options
  • Save josharagon/209eb30152a9bad3da5d4992ca680c67 to your computer and use it in GitHub Desktop.
Save josharagon/209eb30152a9bad3da5d4992ca680c67 to your computer and use it in GitHub Desktop.
crates.io tracklist scraper
function extractTrackLinks(temp) {
const doc = document.createElement('div');
doc.innerHTML = temp.outerHTML;
const tracks = doc.querySelectorAll('.tracks tr:not(.headerRow)');
if (tracks.length === 0) {
console.log("No tracks found in the table.");
return;
}
const trackLinks = [];
for (let i = 0; i < tracks.length; i++) {
const track = tracks[i];
const trackLink = track.querySelector('td:nth-child(3) a').getAttribute('href');
if (trackLink) {
trackLinks.push("https://www.beatport.com" + trackLink);
}
}
// Join the track links array into a single string with line breaks
return trackLinks.join('\n');
}
const allTrackLinks = extractTrackLinks(temp1);
console.log(allTrackLinks);
@josharagon
Copy link
Author

josharagon commented Mar 19, 2024

store .tracks table element as global var

run extractArtistTitle(temp1) etc..

@josharagon
Copy link
Author

update - return all track ids for beatport.

can use soundiiz to auto add to playlist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment