├── README.md └── google_takeout.js /README.md: -------------------------------------------------------------------------------- 1 | # GoogleTakeoutAutoDownload 2 | 3 | A simple Node.js script to automate download of your Google Takeout data using puppeteer. 4 | -------------------------------------------------------------------------------- /google_takeout.js: -------------------------------------------------------------------------------- 1 | const puppeteer = require('puppeteer'); 2 | const jsonfile = require('jsonfile') 3 | const fs = require('fs') 4 | function waitFor2FA(page) { 5 | return new Promise(function (resolve, reject) { 6 | (function waitForURL() { 7 | if (page.url() === 'https://takeout.google.com/') { 8 | console.log("MET!") 9 | return resolve() 10 | } 11 | else { 12 | console.log(page.url()) 13 | setTimeout(waitForURL, 3000); 14 | } 15 | })(); 16 | }); 17 | } 18 | 19 | (async () => { 20 | const browser = await puppeteer.launch({ headless: false }) 21 | const page = await browser.newPage() 22 | const cookiesFilePath = 'PATH_TO_COOKIE' 23 | const previousSession = fs.existsSync(cookiesFilePath) 24 | if (previousSession) { 25 | // If file exist load the cookies 26 | const cookiesArr = require(`${cookiesFilePath}`) 27 | if (cookiesArr.length !== 0) { 28 | for (let cookie of cookiesArr) { 29 | // await page.setCookie(cookie) 30 | } 31 | console.log('Session has been loaded in the browser') 32 | } 33 | } 34 | await page.setViewport({ width: 1280, height: 800 }) 35 | await page.goto('https://takeout.google.com/') 36 | 37 | await page.waitForSelector('input[type="email"]') 38 | await page.type('input[type="email"]', "EMAIL") 39 | await page.click('#identifierNext') 40 | 41 | await page.waitForSelector('input[type="password"]', { visible: true }) 42 | await page.type('input[type="password"]', "PASSWORD") 43 | await page.click('#passwordNext') 44 | 45 | await waitFor2FA(page) 46 | 47 | await page.waitForSelector('button[aria-label="Deselect all"]') 48 | await page.click('button[aria-label="Deselect all"]') 49 | 50 | // We need location history only. 51 | await page.evaluate(() => { 52 | // Add more for other data 53 | document.querySelector('input[type="checkbox"][name="Location History"]').click() 54 | document.querySelector('button[aria-label="Next step"]').click() 55 | }) 56 | await page.waitForSelector('button[jsname="DU7EXd"]', { visible: true }) 57 | 58 | // Make archive 59 | await page.evaluate(() => { 60 | document.querySelector('button[jsname="DU7EXd"]').click() 61 | }) 62 | await page.waitForNavigation({ timeout: 0 }) 63 | await page.evaluate(() => { 64 | // Click the first download button i.e. the latest one (just archived) 65 | document.querySelector('.WpHeLc').click() 66 | }) 67 | 68 | // Save Session Cookies 69 | const cookiesObject = await page.cookies() 70 | console.log(cookiesObject) 71 | // Write cookies to temp file to be used in other profile pages 72 | jsonfile.writeFile(cookiesFilePath, cookiesObject, { spaces: 2 }, 73 | function (err) { 74 | if (err) { 75 | console.log('The file could not be written.', err) 76 | } 77 | console.log('Session has been successfully saved') 78 | }) 79 | 80 | })() 81 | --------------------------------------------------------------------------------