Skip to content

Instantly share code, notes, and snippets.

@plonknimbuzz
Last active July 29, 2021 18:12
Show Gist options
  • Save plonknimbuzz/a4c0e7cc1da48750406c22a73f5480b4 to your computer and use it in GitHub Desktop.
Save plonknimbuzz/a4c0e7cc1da48750406c22a73f5480b4 to your computer and use it in GitHub Desktop.
Download google maps image using web console
/*
just for urgent needed, dont spam this.
Just copy this script into web console and run the function.
If you want to download the image, just edit downloadFile=true
Note:
- workflow: get all image src or div background-image, then filter it as our needs
- you can edit this file to scrape another website if you want. just change my regex or remove it
Usage:
1 open google maps url like : https://www.google.com/maps/place/Mloko+Sewu/@-7.79157,111.6462699,3a,75y,90t/data=!3m8!1e2!3m6!1sAF1QipMtMGxW_muPjPM5RZQhCoOWlnlUdxv_tyfoC3w!2e10!3e12!6shttps:%2F%2Flh5.googleusercontent.com%2Fp%2FAF1QipMtMGxW_muPjPM5RZQhCoOWlnlUdxv_tyfoC3w%3Dw203-h121-k-no!7i4000!8i2403!4m5!3m4!1s0x2e79a5eb33449f27:0xfdee7e62b1634c5!8m2!3d-7.79157!4d111.6462699
2 open your web console using F12
3 copy paste this script into webconsole
4 type getAllImage(false, false) to display only or getAllImage(false,true) to download the images
5 scroll google maps down (if any images left) then do the 4th action again
*/
window.getAllImage = function(repeatedFile=false, downloadFile=false){
window.gmap_images = (window.gmap_images && !repeatedFile)?window.gmap_images:[];
document.querySelectorAll('img,div').forEach(function(e){
var src = e.getAttribute('src');
if(!src){
var style = e.currentStyle || window.getComputedStyle(e, false);
src = style.backgroundImage.slice(4, -1).replace(/"/g, "");
}
if(/googleusercontent\.com\/p\//.test(src)) {
var exp = src.split('=');
if(!window.gmap_images.includes(exp[0])){
window.gmap_images.push(exp[0]);
var url = exp[0]+'=s5120';
console.log(url);
if(downloadFile){
fetch(url)
.then(resp => resp.blob())
.then(blob => {
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
// the filename you want
a.download = 'google-image.jpeg';
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
})
.catch(() => console.log('failed: '+url));
}
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment