-
Notifications
You must be signed in to change notification settings - Fork 0
/
eastmoney.js
49 lines (47 loc) · 1.75 KB
/
eastmoney.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
39
40
41
42
43
44
45
46
47
48
49
var cheerio = require('cheerio')
var rp = require('request-promise')
var options = {
uri: 'https://www.eastmoney.com',
transform: function (body) {
return cheerio.load(body);
}
}
//获得二级目录信息
function getTexts(newsArr, news, callback) {
var options = {
uri: news.link,
transform: function (body) {
return cheerio.load(body);
}
}
rp(options).then(function ($) {
var item = $('.newsContent', 'div');
news.time = item.find('.time', 'div').first().text();
news.editor = item.find('.author', 'div').first().text();
news.source = item.find('.source', 'div').text();
var source = news.source;
news.source = source.replace(/\s*/g, '');
news.comment = item.find('.num', 'span').text();
news.contain = item.find('.b-review', 'div').text();
var maintext = '';
$('.newsContent', 'div').find('.Body', 'div').children('p').each(function (idx, element) {
maintext = maintext.concat($(element).text());
})
news['texts'] = maintext;
console.log(news);
})
}
rp(options).then(function ($) {
var newsArr = [];
var item = $('.nlist', 'div').find('li').children('a')
item.map(function (idx, element) {
var news = {};
news.title = $(element).text();
news.link = $(element).attr('href');
getTexts(newsArr, news, function(newsArr, news) {
console.log(news);
newsArr.push(news);
});
})
//console.log(newsArr);
})