Skip to content

Instantly share code, notes, and snippets.

@callado4
Forked from bryant988/zillow.js
Last active October 29, 2023 03:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save callado4/678385890df47a35553f11d948b34ec4 to your computer and use it in GitHub Desktop.
Save callado4/678385890df47a35553f11d948b34ec4 to your computer and use it in GitHub Desktop.
Zillow Image Downloader
/*
Open up vertical photo gallery and scroll all the way to the bottom
*/
const script33 = document.createElement('script');
script33.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
script33.onload = () => {
$ = jQuery.noConflict();
function biggestSrc(srcset) {
if (srcset == undefined) { return ""; }
const srcs = srcset.split(' ');
return srcs[srcs.length - 2];
}
const imageList = $('div.vertical-gallery-wrapper img').map((i,e) => biggestSrc($(e).attr('srcset'))).get();
// const imgs = $('div.vertical-gallery-wrapper img')
console.log('imageList', imageList.length, imageList);
const delay = ms => new Promise(res => setTimeout(res, ms)); // promise delay
// get all image blobs in parallel first before downloading for proper batching
Promise.all(imageList.map(i => fetch(i))).then(responses =>
Promise.all(responses.map(res => res.blob()))
).then(async (blobs) => {
for (let i = 0; i < blobs.length; i++) {
if (i % 10 === 0) {
console.log('1 sec delay...');
await delay(1000);
}
let a = document.createElement('a');
a.style = "display: none";
console.log(i);
let url = window.URL.createObjectURL(blobs[i]);
a.href = url;
const picNum = (i+1)
if (picNum < 10) {
a.download = '0' + picNum + '';
} else {
a.download = picNum + '';
}
document.body.appendChild(a);
a.click();
setTimeout(() => {
window.URL.revokeObjectURL(url);
}, 100);
}
});
};
document.getElementsByTagName('head')[0].appendChild(script33);
/**
* NOTE: this specifically works if the house is for sale since it renders differently.
* This will download the highest resolution available per image.
*/
/**
* STEP 1: Make sure to *SCROLL* through all images so they appear on DOM.
*/
/**
* STEP 2: Make sure to *SCROLL* through all images so they appear on DOM.
* Click on the first image
*/
/**
* STEP 3: Open Dev Tools Console.
* Copy and paste code below
*/
const script = document.createElement('script');
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
script.onload = () => {
$ = jQuery.noConflict();
// can't map since there isn't a list, so just push as we find more.
const imageList = [];
// while there is a next button
while ($('svg.icon-arrow-right').length || $('svg.icon-reload').length) {
const srcset = $('.hdp-photo-gallery-lightbox-content .hdp-gallery-image-content:visible source[type="image/jpeg"]').attr('srcset');
console.log('srcset is', srcset);
// no more images available so stop looping
if (srcset == undefined) {
break;
}
const srcs = srcset.split(' ');
const src = srcs[srcs.length - 2];
// just in case... let make sure the src is not already in the list.
if (imageList.indexOf(src) === -1) {
imageList.push(src);
}
// console.log('imageList is', imageList);
// Last image, break out of loop
if ($('svg.icon-reload').length) {
break;
}
// go to the next slide
$('svg.icon-arrow-right').parent().parent().click();
}
// console.log('imageList is', imageList);
const delay = ms => new Promise(res => setTimeout(res, ms)); // promise delay
// get all image blobs in parallel first before downloading for proper batching
Promise.all(imageList.map(i => fetch(i))).then(responses =>
Promise.all(responses.map(res => res.blob()))
).then(async (blobs) => {
for (let i = 0; i < blobs.length; i++) {
if (i % 10 === 0) {
console.log('1 sec delay...');
await delay(1000);
}
let a = document.createElement('a');
a.style = "display: none";
console.log(i);
let url = window.URL.createObjectURL(blobs[i]);
a.href = url;
const picNum = (i+1)
if (picNum < 10) {
a.download = '0' + picNum + '';
} else {
a.download = picNum + '';
}
document.body.appendChild(a);
a.click();
setTimeout(() => {
window.URL.revokeObjectURL(url);
}, 100);
}
});
};
document.getElementsByTagName('head')[0].appendChild(script);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment