Skip to content

Instantly share code, notes, and snippets.

@nacgarg nacgarg/scrape.js
Created Jun 9, 2019

Embed
What would you like to do?
Scrape PPs from ScoreSaber
const request = require('request');
const parse = require('node-html-parser').parse;
const fs = require('fs');
const Promise = require('bluebird');
const LAST_PAGE = 3820
var getPPs = function(pageNum, file) {
// return an array of PPs on that page
return new Promise((resolve, reject) => {
console.log(pageNum)
request('https://scoresaber.com/global/'+pageNum, (err, res, body) => {
if (err) { reject(err) }
const root = parse(body);
let pps = root.querySelectorAll('.ppValue').map(e=>parseFloat(e.rawText.replace(/,/g, '')));
fs.writeFileSync(file, pps.join("\n")+"\n")
resolve(pps);
});
})
}
outFile = fs.openSync('data.csv', 'a')
pages = []
for (var i = 1; i < LAST_PAGE; i++) {
pages.push(i)
}
Promise.map(pages, function (i) {
return getPPs(i, outFile);
}, {concurrency: 5})
.then(function(allResults){
console.log(allResults)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.