Skip to content

Instantly share code, notes, and snippets.

@tmlbl
Last active August 29, 2015 14:14
Show Gist options
  • Save tmlbl/7ea00806a1bf5294646b to your computer and use it in GitHub Desktop.
Save tmlbl/7ea00806a1bf5294646b to your computer and use it in GitHub Desktop.
Parsing Neighborhood Information from Zillow
[ { title: 'Makin\' It Singles',
name: 'Upper-scale urban singles.',
description: 'Pre-middle-age to middle-age singles with upper-scale incomes. May or may not own their own home. Most have college educations and are employed in mid-management professions.' },
{ title: 'Aspiring Urbanites',
name: 'Urban singles with moderate income.',
description: 'Low- to middle-income singles over a wide age range. Some have a college education. They work in a variety of occupations, including some management-level positions.' },
{ title: 'Bright Lights, Big City',
name: 'Very mobile singles living in the city.',
description: 'Singles ranging in age from early 20s to mid-40s who have moved to an urban setting. Most rent their apartment or condo. Some have a college education and work in services and the professional sector.' } ]
var get = require('request').get,
xml = require('libxmljs');
function Zillow() { }
const ZWSID = 'X1-ZWz1az5tn97taj_4n5nu';
const baseUrl = 'http://www.zillow.com/webservice/' +
'GetDemographics.htm?zws-id=' + ZWSID + '&state=WA&' +
'city=Seattle&neighborhood=';
Zillow.prototype.getNeighborhoodGroups = function (hood_name, cb) {
var fullUrl = baseUrl + hood_name;
get(fullUrl, function (err, res, xmlString) {
var doc = xml.parseXmlString(res.body);
var groups = doc.get('//segmentation').childNodes();
cb(null, groups.map(function (grp) {
return {
title: grp.get('./title').text(),
name: grp.get('./name').text(),
description: grp.get('./description').text()
};
}));
});
};
new Zillow().getNeighborhoodGroups('Ballard', function (err, groups) {
console.dir(groups);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment