-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscraper.js
42 lines (38 loc) · 1.25 KB
/
scraper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var fs = require('fs');
var request = require('request');
var cheerio = require('cheerio');
scraper = {
scrape: function (req, reply) {
url = 'http://www.showmeboone.com/sheriff/JailResidents/JailResidents.asp';
request(url, function(error, response, html){
if(!error){
var $ = cheerio.load(html);
var inmates = [];
var rows = $('.resultsTable').children('tr').toArray();
rows.shift();
rows.forEach(function(row){
var inmateData = $(row).children('td');
var inmate = {
last_name: $(inmateData).eq(0).text(),
first_name: $(inmateData).eq(1).text(),
middle_name: $(inmateData).eq(2).text(),
gender: $(inmateData).eq(3).text(),
race: $(inmateData).eq(4).text(),
age: $(inmateData).eq(5).text(),
city: $(inmateData).eq(6).text(),
state: $(inmateData).eq(7).text()
}
inmates.push(inmate);
});
}
else {
response.send(error);
}
fs.writeFile('output.json', JSON.stringify(inmates, null, 2), function(err){
console.log('File successfully written to output.json');
});
reply(inmates);
});
}
}
module.exports = scraper;