-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (24 loc) · 864 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
34
var request = require('request');
var cheerio = require('cheerio');
var url = 'https://www.npmjs.com/package/q';
request(url, function(error, response, html){
if(!error){
// request ile çağırdığımız urlden gelen html datayı '$' olarak yeniden tanımlıyoruz.
var $ = cheerio.load(html);
// Çıktı için json objesi oluşturuyorum
var json = {};
$('.package-name').filter(function(){
json.title = $(this).text().trim()
});
$('.package-description').filter(function(){
json.desc = $(this).text().trim()
});
$('.box li').eq(2).filter(function(){
json.repo = $(this).text().trim()
});
$('.collaborators').next().next().filter(function(){
json.stats = $(this).children().eq(2).text().replace(/\s+/g, ' ').trim();
});
console.log(JSON.stringify(json, null, 4));
}
});