Skip to content

Instantly share code, notes, and snippets.

@markhker
Created October 20, 2021 00:50
Show Gist options
  • Save markhker/cf1b31af5311430ca87759aad87a9e1c to your computer and use it in GitHub Desktop.
Save markhker/cf1b31af5311430ca87759aad87a9e1c to your computer and use it in GitHub Desktop.
Zillow Download images
/**
* STEP 1: Click on the first image to open the image lightbox carousel
*/
/**
* STEP 2: Open Dev Tools Console.
* Copy and paste code below, replace the query variables if they changed
* This will download the images in webp and jpg
*/
var downloadZillowImages = async () => {
var carouselCounterQuery = '.hdp-gallery-image .zsg-carousel-counter'
var nextButtonQuery = '.gallery-lightbox-nav .photo-carousel-right-arrow button'
var pictureQuery = '.hdp-gallery-image:not(.zsg-hide) picture'
var delay = ms => new Promise(res => setTimeout(res, ms));
var total = +document.querySelector(carouselCounterQuery).textContent.split(' ')[2]
console.log('Total images: ', total)
var nextButton = document.querySelector(nextButtonQuery)
var imageUrls = []
for (var i = 0; i < total; i++) {
var webpImageComponent = document.querySelector(pictureQuery).children[0].srcset.split(' ')
var webpUrl = webpImageComponent[webpImageComponent.length - 2]
if (!imageUrls.includes(webpUrl)) {
imageUrls.push(webpUrl)
}
var jpgImageComponent = document.querySelector(pictureQuery).children[1].srcset.split(' ')
var jpgUrl = jpgImageComponent[jpgImageComponent.length - 2]
if (!imageUrls.includes(jpgUrl)) {
imageUrls.push(jpgUrl)
}
nextButton.click()
}
console.log(imageUrls)
Promise.all(imageUrls.map(url => fetch(url)))
.then(responses => Promise.all(responses.map(res => res.blob())))
.then(async blobs => {
for (var j = 0; j < blobs.length; j++) {
if (j % 10 === 0) {
console.log('1 sec delay...')
await delay(1000)
}
var url = window.URL.createObjectURL(blobs[j])
var a = document.createElement('a')
a.style = 'display: none';
a.href = url
a.download = j + ''
document.body.appendChild(a)
a.click()
setTimeout(() => {
window.URL.revokeObjectURL(url)
}, 100)
}
})
}
/**
* STEP 3: Execute, enjoy
*/
downloadZillowImages()
@tdlm
Copy link

tdlm commented Dec 10, 2021

Worked flawlessly. Thank you.

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