Skip to content

Instantly share code, notes, and snippets.

@oscarmorrison
Created November 11, 2016 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oscarmorrison/021b8e7cc2609b8de105f57e126f7c35 to your computer and use it in GitHub Desktop.
Save oscarmorrison/021b8e7cc2609b8de105f57e126f7c35 to your computer and use it in GitHub Desktop.
Boston Sports Club Scrape
/*jslint node: true */
/*jshint esversion: 6 */
'use strict';
var Nightmare = require('nightmare');
var moment = require('moment');
var debug = false;
var nightmare = new Nightmare({
show: debug,
dock: debug,
webPreferences: {
partition: 'noPerist'
}
});
let url = 'https://www.mysportsclubs.com/account/checkins';
let username = 'YOUR_BSC_EMAIL';
let password = 'YOUR_BSC_PASSWORD';
nightmare
.goto(url)
.type('input#username', username)
.type('input#password', password)
.click('#_submit')
.wait('.checkins-container')
.evaluate(function () {
return document.querySelector('.checkins-container').innerText;
})
.end()
.then(cleanData)
.then(modelData)
.catch(function (error) {
console.error('Search failed:', error);
});
function cleanData(data){
data = data
.replace(/^\s*\n/gm,"")
.split('\n')
.filter(n => n);
data.shift();
return data;
}
function modelData(data) {
data = data.reverse();
var newData = [];
var id = 1;
for(var i = 0; i < data.length; i=i+3) {
var checkin = {
id: id,
location: data[i+2],
datetime: formatDate(data[i+1], data[i])
};
newData.push(checkin);
id += 1;
}
console.log(newData);
return newData;
}
function formatDate(date, time) {
var newDate = moment(date+' '+time, "MM-DD-YYYY hh:mm a");
return newDate.format();
}
{
"name": "mysportsclubscrape",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"moment": "^2.15.2",
"nightmare": "^2.7.0"
},
"devDependencies": {
"nightmare": "^2.7.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment