Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A little script to import starred places saved as geoJSON data from Google Maps. Could be better. Works.
// This script is meant to import Google Maps starred places into
// another Google account.
// Given a geoJSON file of Google Maps starred places (places.json)
// exported by Google takeout (account backup) this script should
// open each place URL and manually click save.
// Upon first run, it's best to stop it and manually login to your
// Google account otherwise you'll run into a non-verified device
// issue. Run again and it should continue through with problems.
// Make sure to enter you Google account name and password (purge after use!)
// To init, run npm i -D puppeteer and then node scrape.js
const puppeteer = require('puppeteer');
const fs = require('fs');
const GOOGLE_ACCOUNT_ID = '';
const GOOGLE_ACCOUNT_PASS = '';
const jsonFile = fs.readFileSync(__dirname + '/places.json');
const jsonData = JSON.parse(jsonFile);
let scrape = async () => {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
await page.goto('https://accounts.google.com/', {waitUntil: 'networkidle2'});
const result = await page.evaluate(() => {
document.getElementById('identifierId').value = GOOGLE_ACCOUNT_ID;
document.getElementById('identifierNext').click();
window.setTimeout(function(){
document.querySelectorAll("[name='password'")[0].value = GOOGLE_ACCOUNT_PASS;
document.getElementById('passwordNext').click();
}, 250);
return;
});
await page.waitFor(4000)
for (let index in jsonData.features) {
let place = jsonData.features[index].properties["Google Maps URL"];
let name = jsonData.features[index].properties["Location"]["Business Name"];
await page.goto(place, {waitUntil: 'networkidle2'});
await page.evaluate(() => {
if (typeof(document.querySelectorAll("[aria-label='SAVE']")[0]) != 'undefined') {
document.querySelectorAll("[aria-label='SAVE']")[0].click();
window.setTimeout(function(){
document.querySelectorAll("[data-index='2']")[0].click();
}, 50);
console.log('Added "' + name + '" to your starred places!');
} else {
console.log('Skipping "' + name + '" as it was already starred…');
}
return;
});
await page.waitFor(200)
}
browser.close();
return;
};
scrape().then((value) => {
console.log('All done!');
});
@robinnorth
Copy link

robinnorth commented May 5, 2021

@benjibee, yeah it's very much a one-time use kinda tool, isn't it? I have now successfully migrated my old Google Workspace account to a new personal Google account using it, saving me the pain of losing all my starred places and custom lists I'd spent years accumulating, so it was indeed very helpful, thanks!

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