-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScraper.js
38 lines (32 loc) · 896 Bytes
/
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
const http = require('http');
function Scraper() {
};
Scraper.prototype.scrape = function(country) {
var promise = new Promise(function(resolve, reject) {
var options, page;
page = '';
if(country.toUpperCase() == 'UK' || country == 'United Kingdom') {
country = 'Great+Britain'
} else if(country.toUpperCase() == 'US' || country.toUpperCase == 'USA' || country == 'America') {
country = 'U.S.A.'
}
options = {
'host': 'www.thomas-bayer.com',
'path': `/restnames/namesincountry.groovy?country=${country.replace(/\s/g, "+")}`,
'port': 80
};
http.get(options, function(resp) {
resp.setEncoding('utf8');
resp.on('data', function(chunk) {
page += chunk;
});
resp.on('end', function() {
resolve(page);
});
}).on("error", function(err) {
reject(err.message);
});
});
return promise
};
module.exports = Scraper;