feat: add 10000link news fulltext (#2681)

Co-authored-by: DIYgod <diy.d.god@gmail.com>
This commit is contained in:
Cloud
2019-07-25 11:32:51 +08:00
committed by DIYgod
parent 058a5ee5f3
commit 5e9c6726e8
3 changed files with 78 additions and 0 deletions

View File

@@ -928,6 +928,17 @@ type 为 all 时category 参数不支持 cost 和 free
</Route>
## 万联网
### 资讯
<Route author="kt286" example="/10000link/news/My01" path="/10000link/news/:category?" :paramsDesc="['栏目代码, 默认为全部']">
| 全部 | 天下大势 | 企业动态 | 专家观点 | 研究报告 |
| ---- | -------- | -------- | -------- | -------- |
| (空) | My01 | My02 | My03 | My04 |
</Route>
## 维基百科
### 中国大陆新闻动态

View File

@@ -1556,6 +1556,9 @@ router.get('/wikihow/category/:category/:type', require('./routes/wikihow/catego
router.get('/getitfree/category/:category?', require('./routes/getitfree/category.js'));
router.get('/getitfree/search/:keyword?', require('./routes/getitfree/search.js'));
// 万联网
router.get('/10000link/news/:category?', require('./routes/10000link/news'));
// Artand
router.get('/artand/user/work/:uid', require('./routes/artand/user/work'));

View File

@@ -0,0 +1,64 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const url = require('url');
const { addNoReferrer } = require('@/utils/common-utils');
module.exports = async (ctx) => {
const category = ctx.params.category;
const pageUrl = `http://info.10000link.com/newslists.aspx?chid=${category}`;
const host = 'http://info.10000link.com';
const response = await got({
method: 'get',
url: pageUrl,
});
const $ = cheerio.load(response.data);
const list = $('.l_newshot li').get();
const ProcessFeed = async (link) => {
const response = await got({
method: 'get',
url: link,
});
const $ = cheerio.load(response.data);
addNoReferrer($, '#news_body');
return $('#news_body').html();
};
const items = await Promise.all(
list.map(async (item) => {
const $ = cheerio.load(item);
const $a = $('h1 a');
const link = url.resolve(host, $a.attr('href'));
const cache = await ctx.cache.get(link);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const description = await ProcessFeed(link);
const single = {
title: $a.text(),
description,
link: link,
pubDate: new Date($('.ymd_w').text()).toUTCString(),
author: $('.day-lx span:first-child').text(),
};
ctx.cache.set(link, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `万联网 ${$('.t-h2')
.text()
.replace(' |资讯频道', '')}`,
link: pageUrl,
description: $('meta[name="Description"]').attr('content'),
item: items,
};
};