Skip to content

Instantly share code, notes, and snippets.

@aarmora
Last active May 27, 2021 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aarmora/f0ca8caace04324fdfa31e6b06797714 to your computer and use it in GitHub Desktop.
Save aarmora/f0ca8caace04324fdfa31e6b06797714 to your computer and use it in GitHub Desktop.
This gets additional property info for distressed properties.
// Run this function at the following url:
// https://kingcounty.gov/depts/finance-business-operations/treasury/foreclosure/current-foreclosure-action/foreclosure-properties.aspx
async function getAllProperties(copy) {
const data = await fetch("https://data.kingcounty.gov/api/views/nx4x-daw6/rows.json", {
"headers": {
"accept": "application/json, text/javascript, */*; q=0.01",
"sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"90\", \"Google Chrome\";v=\"90\"",
"sec-ch-ua-mobile": "?0"
},
"referrer": "https://kingcounty.gov/",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": null,
"method": "GET",
"mode": "cors",
"credentials": "omit"
});
const body = await data.json();
const properties = body.data.map(property => property[8]);
copy(properties);
}
// Pass in dev tools copy function
await getAllProperties(copy);
// Run this function at the following url:
// https://blue.kingcounty.com/Assessor/eRealProperty/Detail.aspx?ParcelNbr=055500007004
async function getProperty(parcelNumber) {
const url = `https://blue.kingcounty.com/Assessor/eRealProperty/Detail.aspx?ParcelNbr=${parcelNumber}`;
const response = await fetch(url, {
"headers": {
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"accept-language": "en-US,en;q=0.9,pt-BR;q=0.8,pt;q=0.7",
"cache-control": "max-age=0",
"sec-ch-ua": "\" Not A;Brand\";v=\"99\", \"Chromium\";v=\"90\", \"Google Chrome\";v=\"90\"",
"sec-ch-ua-mobile": "?0",
"sec-fetch-dest": "document",
"sec-fetch-mode": "navigate",
"sec-fetch-site": "none",
"sec-fetch-user": "?1",
"upgrade-insecure-requests": "1"
},
"referrerPolicy": "strict-origin-when-cross-origin",
"body": null,
"method": "GET",
"mode": "cors",
"credentials": "include"
});
let html = await response.text();
html = $.parseHTML(`<div id="cobalt-int-part'>${html.split('<body id="body">')[1].split('</body>')[0]}</div>`);
$('#contentcol').html(html);
const property = {
parcelNumber: parcelNumber,
propertyLocation: $('#cphContent_DetailsViewParcel tr:nth-of-type(3) td:nth-of-type(2)').text(),
landUse: $('#cphContent_DetailsViewLand tr:nth-of-type(1) td:nth-of-type(2)').text(),
yearBuilt: $('#cphContent_DetailsViewResBldg tr:nth-of-type(2) td:nth-of-type(2)').text(),
condition: $('#cphContent_DetailsViewResBldg tr:nth-of-type(8) td:nth-of-type(2)').text(),
beds: $('#cphContent_DetailsViewResBldg tr:nth-of-type(22) td:nth-of-type(2)').text(),
fullBaths: $('#cphContent_DetailsViewResBldg tr:nth-of-type(23) td:nth-of-type(2)').text(),
assessorUrl: url
};
return property;
}
async function getAllProperties() {
const populatedProperties = [];
for (let i = 0; i < properties.length; i++) {
const property = properties[i];
const populatedProperty = await getProperty(property);
populatedProperties.push(populatedProperty);
await timeout(1000);
}
return populatedProperties;
}
function timeout(ms) {
return new Promise(res => setTimeout(res, ms));
}
copy(await getAllProperties());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment