Created
June 22, 2022 18:46
-
-
Save duplaja/3f560cd28c7d9298719388c81d1ab6ba to your computer and use it in GitHub Desktop.
Scrape RYM Charts - 6-22-22
This file contains hidden or 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
function generateDownload(filename, text, type='text/plain;charset=utf-8') { | |
// Create an invisible A element | |
const a = document.createElement('a'); | |
a.style.display = 'none'; | |
document.body.appendChild(a); | |
var BOM = new Uint8Array([0xEF,0xBB,0xBF]); | |
// Set the HREF to a Blob representation of the data to be downloaded | |
a.href = window.URL.createObjectURL( | |
new Blob([BOM, text], { type }) | |
); | |
// Use download attribute to set set desired file name | |
a.setAttribute('download', filename); | |
// Trigger the download by simulating click | |
a.click(); | |
// Cleanup | |
window.URL.revokeObjectURL(a.href); | |
document.body.removeChild(a); | |
} | |
function startDownload() { | |
const collection = document.getElementsByClassName('page_charts_section_charts_top_line'); | |
let origTitle = 'RYM Chart Download'; | |
let today = new Date().toISOString().replace(/T.*/,''); | |
let lowerTitle = origTitle.toLowerCase(); | |
let title = lowerTitle.replace(/[^a-z0-9]/gi, '')+'-'+today+'.txt'; | |
var fullList = ''; | |
for (let i = 0; i < collection.length; i++) { | |
artist = collection[i].getElementsByClassName('page_charts_section_charts_item_credited_links_primary')[0].innerText; | |
album = collection[i].getElementsByClassName('page_charts_section_charts_item_title')[0].innerText; | |
content = artist +' - '+ album | |
fullList = fullList+content; | |
if(i != parseInt(collection.length) - 1) { | |
fullList=fullList+'\r\n'; | |
} | |
} | |
generateDownload(title, fullList); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment