Created
March 29, 2023 19:21
-
-
Save ZacharyJacobCollins/7e8352f18e75846d87bfa816a067887e to your computer and use it in GitHub Desktop.
Zillow Scrape
This file contains hidden or 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
let entries = []; | |
let selectorIds = [ | |
{ | |
'title': 'HomeValueIndex', | |
'dataTypeElId': 'median-home-value-zillow-home-value-index-zhvi-dropdown-1', | |
'geographyElId': 'median-home-value-zillow-home-value-index-zhvi-dropdown-2', | |
}, | |
{ | |
'title': 'RentalIndex', | |
'dataTypeElId': 'rental-values-dropdown-1', | |
'geographyElId': 'rental-values-dropdown-2' | |
}, | |
{ | |
'title': 'InventorylistingsSales', | |
'dataTypeElId': 'home-sales-listings-dropdown-1', | |
'geographyElId': 'home-sales-listings-dropdown-2' | |
}, | |
{ | |
'title': 'More Metrics', | |
'dataTypeElId': 'more-metrics-dropdown-1', | |
'geographyElId': 'more-metrics-dropdown-2' | |
}, | |
]; | |
function getDataTypes() { | |
selectorIds.forEach(function (selector) { | |
console.log(selector.dataTypeElId) | |
let dataTypes = Array.from(document.getElementById(selector.dataTypeElId).children); | |
dataTypes.forEach(function(item) { | |
let geographies = getGeographies(selector) | |
geographies.forEach(function (entry) { | |
entries.push({ | |
"title": selector.title, | |
data_type: item.innerText, | |
geography: entry.geography, | |
url: entry.url | |
}) | |
}) | |
}); | |
console.log(entries.length) | |
console.log(entries) | |
downloadJsonFile(entries, selector); | |
}) | |
} | |
function getGeographies(selector) { | |
let geographies = []; | |
let elements = Array.from(document.getElementById(selector.geographyElId).children) | |
elements.forEach(function(item) { | |
geographies.push({ | |
"geography": item.innerText, | |
"url": item.value | |
}); | |
}); | |
return geographies; | |
} | |
function downloadJsonFile(entries, selector) { | |
var a = document.createElement('a'); | |
a.setAttribute('id', 'downloadAnchorElem'); | |
document.body.appendChild(a); | |
let dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(entries)); | |
a.setAttribute("href", dataStr); | |
a.setAttribute("download", "Zillow" + selector.title + "DataMap.json"); | |
a.click(); | |
} | |
getDataTypes() | |
console.log(entries) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment