Created
October 20, 2021 00:50
-
-
Save markhker/cf1b31af5311430ca87759aad87a9e1c to your computer and use it in GitHub Desktop.
Zillow Download images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Worked flawlessly. Thank you.