Created
March 30, 2017 13:44
-
-
Save yousefamar/cc6502664e89b7849895784ad6603572 to your computer and use it in GitHub Desktop.
Google MyActivity Scraper
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 username = ''; | |
const password = ''; | |
require('nightmare')() | |
.goto('https://accounts.google.com/Login?continue=https://myactivity.google.com/item') | |
.wait('#Email') | |
.insert('#Email', username) | |
.click('#next') | |
.wait('#Passwd') | |
.insert('#Passwd', password) | |
.click('#signIn') | |
.wait('#main-content', 1000) | |
.evaluate(function () { | |
const obj2array = obj => Object.keys(obj).map(k => obj[k]); | |
const isArray = arr => arr instanceof Array; | |
const isObj = obj => obj && typeof obj === 'object' && !isArray(obj); | |
const ctrl = angular.element(document.querySelector('#main-content')).controller(); | |
const items = obj2array(ctrl).filter(i => isArray(i) && i.length && !('date' in i[0]))[0]; | |
const data = items.map((item) => { | |
const data = obj2array(item) | |
.filter(isObj) | |
.map(obj2array) | |
.filter(i => i.length)[0] | |
.map(obj2array) | |
.filter(i => i.length); | |
return { | |
action: data[0].filter(isArray)[0][0], | |
subject: data[1].filter(isArray)[0][0], | |
location: (data.length < 3 || !isArray(data[2]) || !data[2][0]) ? null : { | |
human: obj2array(data[2][0]).filter(isArray)[0][0], | |
gps: (m => { return { x: +m[0], y: +m[1] }; })(obj2array(data[2][0]).filter(isArray)[0][1].match(/-?\d*\.{0,1}\d+/g)) | |
} | |
}; | |
}); | |
return data; | |
}) | |
.end() | |
.then(function (result) { | |
console.log(JSON.stringify(result, null, ' ')); | |
}) | |
.catch(function (error) { | |
console.error('Error:', error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment