-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhtmlListingScraper.js
More file actions
40 lines (31 loc) · 1.01 KB
/
Copy pathhtmlListingScraper.js
File metadata and controls
40 lines (31 loc) · 1.01 KB
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
const cheerio = require('cheerio');
const deepCopy = require('deepCopy');
const {getListingHtml} = require('./requestHelpers');
function parseString(str) {
if (isNaN(str)) {
return str;
}
return parseInt(str);
}
function htmlListingScraper(listing) {
return getListingHtml(listing.RelativeDetailsURL)
.then(html => {
let newListing = deepCopy(listing);
let detailedInfo = {};
$ = cheerio.load(html);
$('.m_property_dtl_data_td_val').each((i, elem) => {
const id = elem.attribs.id
.split('m_property_dtl_data_val_').pop()
.split('m_property_dtl_blddata_val_').pop();
const value = $(elem).text();
detailedInfo[id] = parseString(value);
// Get a numeric value for condo fees
if (id === 'monthlymaintenancefees') {
detailedInfo.condoFeesNum = parseString(value.match(/\d+/)[0]);
}
});
newListing.detailedInfo = detailedInfo;
return newListing;
});
}
module.exports = htmlListingScraper;