-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patholdIndex.js
More file actions
74 lines (51 loc) · 1.75 KB
/
oldIndex.js
File metadata and controls
74 lines (51 loc) · 1.75 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var tress = require('tress');
var needle = require('needle');
var cheerio = require('cheerio');
var resolve = require('url').resolve;
var fs = require('fs');
var URL = 'http://constanta.burodizayna.ru/catalog/kutternyie-nozhi/';
var results = [];
var title = [];
//.right-content_item > span.name
needle.get(URL, function(err, res){
if (err) throw err;
// парсим DOM
var $ = cheerio.load(res.body);
$('.right-content_item span.name').each(function() {
title.push($(this).contents().text());
});
var elm = $.html('.right-content_item span.name');
console.log(elm);
});
/*
var q = tress(function(url, callback){
needle.get(url, function(err, res){
if (err) throw err;
// парсим DOM
var $ = cheerio.load(res.body);
//информация о новости
if($('.b_infopost').contents().eq(2).text().trim().slice(0, -1) === 'Алексей Козлов'){
results.push({
title: $('h1').text(),
date: $('.b_infopost>.date').text(),
href: url,
size: $('.newsbody').text().length
});
}
//список новостей
$('.b_rewiev p>a').each(function() {
q.push($(this).attr('href'));
});
//паджинатор
$('.bpr_next>a').each(function() {
// не забываем привести относительный адрес ссылки к абсолютному
q.push(resolve(URL, $(this).attr('href')));
});
callback();
});
}, 10); // запускаем 10 параллельных потоков
q.drain = function(){
fs.writeFileSync('./data.json', JSON.stringify(results, null, 4));
}
q.push(URL);
*/