forked from chengxuanying/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add 经济观察网 (DIYgod#7610)
- Loading branch information
Ethan Shen
authored
Jun 6, 2021
1 parent
8274937
commit 2917652
Showing
3 changed files
with
160 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,84 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const timezone = require('@/utils/timezone'); | ||
|
||
const legacyUrls = { | ||
1: '/yaowen/dashi', | ||
2: '/yaowen/hfggzc', | ||
3: '/jinrong/zhengquan', | ||
4: '/jinrong/ziben', | ||
5: '/jinrong/licai', | ||
6: '/shangye/xinnengyuan', | ||
7: '/shangye/yiliao', | ||
8: '/fcqcxf/dichan', | ||
9: '/fcqcxf/qiche', | ||
10: '/fcqcxf/xiaofei', | ||
11: '/yule/yingshi', | ||
12: '/yule/yule', | ||
13: '/yule/tiyu', | ||
14: '/yule/jiaoyu', | ||
15: '/gcj/guanchajia', | ||
16: '/gcj/zhuanlan', | ||
17: '/gcj/shuping', | ||
18: '/gcj/lishi', | ||
19: '/yaowen/hfshuju', | ||
}; | ||
|
||
module.exports = async (ctx) => { | ||
const category = ctx.params.category || '观察家'; | ||
const category_url_relation = { | ||
'01': 'http://www.eeo.com.cn/yaowen/dashi/', | ||
'02': 'http://www.eeo.com.cn/yaowen/hfggzc/', | ||
'03': 'http://www.eeo.com.cn/jinrong/zhengquan/', | ||
'04': 'http://www.eeo.com.cn/jinrong/ziben/', | ||
'05': 'http://www.eeo.com.cn/jinrong/licai/', | ||
'06': 'http://www.eeo.com.cn/shangye/xinnengyuan/', | ||
'07': 'http://www.eeo.com.cn/shangye/yiliao/', | ||
'08': 'http://www.eeo.com.cn/fcqcxf/dichan/', | ||
'09': 'http://www.eeo.com.cn/fcqcxf/qiche/', | ||
10: 'http://www.eeo.com.cn/fcqcxf/xiaofei/', | ||
11: 'http://www.eeo.com.cn/yule/yingshi/', | ||
12: 'http://www.eeo.com.cn/yule/yule/', | ||
13: 'http://www.eeo.com.cn/yule/tiyu/', | ||
14: 'http://www.eeo.com.cn/yule/jiaoyu/', | ||
15: 'http://www.eeo.com.cn/gcj/guanchajia/', | ||
16: 'http://www.eeo.com.cn/gcj/zhuanlan/', | ||
17: 'http://www.eeo.com.cn/gcj/shuping/', | ||
18: 'http://www.eeo.com.cn/gcj/lishi/', | ||
19: 'http://www.eeo.com.cn/yaowen/hfshuju/', | ||
}; | ||
const column = ctx.params.column || 'shangyechanye'; | ||
const category = ctx.params.category || ''; | ||
|
||
const rootUrl = 'http://www.eeo.com.cn'; | ||
let currentUrl = rootUrl; | ||
|
||
if (parseInt(column)) { | ||
currentUrl += legacyUrls[parseInt(column)]; | ||
} else { | ||
currentUrl += `/${column}/${category}`; | ||
} | ||
|
||
const response = await got({ | ||
method: 'get', | ||
url: category_url_relation[category], | ||
url: currentUrl, | ||
}); | ||
const data = response.data; | ||
const $ = cheerio.load(data); | ||
const list = $('#lyp_article li').get(); | ||
const result = list.map((item) => ({ | ||
title: $(item).find('div span a').text(), | ||
description: $(item).find('div p').text(), | ||
pubDate: new Date().toUTCString(), | ||
link: $(item).find('>a').attr('href'), | ||
})); | ||
|
||
const $ = cheerio.load(response.data); | ||
|
||
const list = $('#lyp_article li div span a') | ||
.slice(0, 15) | ||
.map((_, item) => { | ||
item = $(item); | ||
return { | ||
link: item.attr('href'), | ||
}; | ||
}) | ||
.get(); | ||
|
||
const items = await Promise.all( | ||
list.map( | ||
async (item) => | ||
await ctx.cache.tryGet(item.link, async () => { | ||
const detailResponse = await got({ | ||
method: 'get', | ||
url: item.link, | ||
}); | ||
const content = cheerio.load(detailResponse.data); | ||
|
||
content('.xd-xd-xd-rwm, .xd_zuozheinfo, .xd-lj, .xd-gg').remove(); | ||
|
||
item.title = content('h1').text(); | ||
item.description = content('.xd-nr').html(); | ||
item.pubDate = timezone(new Date(content('.thiszihao-box-add').nextUntil('.cls').find('span').eq(0).text()), +8); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: '经济观察网', | ||
link: 'http://www.eeo.com.cn', | ||
description: '经济观察网是《经济观察报》社倾力制作的全新商业资讯平台', | ||
item: result, | ||
title: $('title').text().replace('_', ' - '), | ||
link: currentUrl, | ||
item: items, | ||
description: '经济观察网是《经济观察报》社倾力制作的全新商业资讯平台,经济观察网冷静理智的报道风格,并糅合最新的网络技术,拥有专业的采编力量以及独家的新闻报道,为您提供及时、便捷、专业的信息服务。', | ||
}; | ||
}; |