Skip to content

Instantly share code, notes, and snippets.

@drudge
Created November 10, 2012 03:48
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drudge/4049778 to your computer and use it in GitHub Desktop.
Save drudge/4049778 to your computer and use it in GitHub Desktop.
Scrape the Spokeo website for details on a phone number
/**
* Module dependencies.
*/
var scraper = require('scraper');
/**
* Base URL to Spokeo reverse phone lookup website.
*/
var BASE_URL = 'http://www.spokeo.com/reverse-phone-lookup/search?s2=t30&p=';
/**
* Scrape the Spokeo website and return details for a given `phone` number
*
* @param {String} phone - Phone number (XXX) XXX-XXXX
* @param {Function} fn
* @api public
*/
function phoneDetails(phone, fn) {
phone = phone || '';
phone = phone.replace(' ', '+');
scraper(BASE_URL + phone, function(err, $) {
if (err) return fn(err, null);
var num = $('.summary_overview .summary_name').text()
, city = $('.summary_overview > .summary_gender_age').text()
, company = $('.summary_description > .summary_list > li:first-child').text()
, type = $('.summary_description > .summary_list > li:last-child').text()
, out = {};
company = company.replace('Company: ', '');
company = company.substr(0, company.indexOf('According to'));
type = type.replace('Type: ', '');
type = type.substr(0, type.indexOf('According to'));
type = type.toLowerCase();
if (!num) {
err = new Error('Could not find details');
return fn(err, null);
}
out.phone = num;
out.location = city;
out.company = company;
out.type = type;
out.comments = [];
$('.telemarketer_section > .complaint').each(function() {
var date = $(this).find('.complaint_date').text()
, caller = $(this).find('.complaint_caller').text()
, type = $(this).find('.complaint_caller_type').text()
, note = $(this).find('.complaint_comment').text();
caller = caller.replace('Caller: ', '');
type = type.replace('Caller Type: ', '');
note = note.replace('\n', '').trim();
out.comments.push({
date: new Date(date)
, caller: caller || 'unknown'
, type: type || 'unknown'
, note: note
});
});
fn(null, out);
});
}
/**
* Expose `phoneDetails`.
*/
module.exports = phoneDetails;
{
"name": "phone-details",
"version": "0.1.0",
"description": "Scrape the Spokeo website for details on a phone number",
"main": "index.js",
"dependencies": {
"scraper": "~0.0.9"
},
"author": "Nicholas Penree",
"license": "MIT"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment