-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
34 lines (31 loc) · 878 Bytes
/
index.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
var request = require ('superagent');
var cheerio = require ('cheerio');
var URL = 'https://confluence.atlassian.com/display/BITBUCKET/What+are+the+Bitbucket+IP+addresses+I+should+use+to+configure+my+corporate+firewall';
function parse (html) {
var $ = cheerio.load(html);
var obj = {};
$('.confluenceTable tbody tr').each(function(){
var left = true;
$(this).find('td').each(function(){
var text = $(this).text().trim();
if (left){
obj.inbounds = obj.inbounds || [];
if (text) obj.inbounds.push(text);
left = false;
} else {
obj.outbounds = obj.outbounds || [];
if (text) obj.outbounds.push(text);
}
});
});
return obj;
}
module.exports = function(cb){
request
.get(URL)
.end(function(err, res){
if (err) return cb(err);
if (res.status != 200) return cb(new Error(res.status));
cb(err, parse(res.text));
});
}