feat: add 求是网 (#6272)
This commit is contained in:
@@ -1277,6 +1277,18 @@ column 为 third 时可选的 category:
|
||||
|
||||
</Route>
|
||||
|
||||
## 求是网
|
||||
|
||||
### 分类
|
||||
|
||||
<Route author="nczitzk" example="/qstheory" path="/qstheory/:category?" :paramsDesc="['分类,见下表']">
|
||||
|
||||
| 网评 | 视频 | 原创 | 经济 | 政治 | 文化 | 社会 | 党建 | 科教 | 生态 | 国防 | 国际 | 图书 | 学习笔记 |
|
||||
| ---- | ---- | ------ | ------- | -------- | ------- | ------- | ---- | ------- | ------- | ------- | ------------- | ----- | -------- |
|
||||
| qswp | qssp | qslgxd | economy | politics | culture | society | cpc | science | zoology | defense | international | books | xxbj |
|
||||
|
||||
</Route>
|
||||
|
||||
## 趣头条
|
||||
|
||||
### 分类
|
||||
|
||||
@@ -3516,6 +3516,9 @@ router.get('/uisdc/news', require('./routes/uisdc/news'));
|
||||
router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt'));
|
||||
router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic'));
|
||||
|
||||
// 求是网
|
||||
router.get('/qstheory/:category?', require('./routes/qstheory/index'));
|
||||
|
||||
// 生命时报
|
||||
router.get('/lifetimes/:category?', require('./routes/lifetimes/index'));
|
||||
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const rootUrl = 'http://www.qstheory.cn/';
|
||||
|
||||
const config = {
|
||||
toutiao: {
|
||||
title: '头条',
|
||||
url: `${rootUrl}/v9zhuanqu/toutiao/index.htm`,
|
||||
},
|
||||
qswp: {
|
||||
title: '网评',
|
||||
url: `${rootUrl}/qswp.htm`,
|
||||
},
|
||||
qssp: {
|
||||
title: '视频',
|
||||
url: `${rootUrl}/qssp/index.htm`,
|
||||
},
|
||||
qslgxd: {
|
||||
title: '原创',
|
||||
url: `${rootUrl}/qslgxd/index.htm`,
|
||||
},
|
||||
economy: {
|
||||
title: '经济',
|
||||
url: `${rootUrl}/economy/index.htm`,
|
||||
},
|
||||
politics: {
|
||||
title: '政治',
|
||||
url: `${rootUrl}/politics/index.htm`,
|
||||
},
|
||||
culture: {
|
||||
title: '文化',
|
||||
url: `${rootUrl}/culture/index.htm`,
|
||||
},
|
||||
society: {
|
||||
title: '社会',
|
||||
url: `${rootUrl}/society/index.htm`,
|
||||
},
|
||||
cpc: {
|
||||
title: '党建',
|
||||
url: `${rootUrl}/cpc/index.htm`,
|
||||
},
|
||||
science: {
|
||||
title: '科教',
|
||||
url: `${rootUrl}/science/index.htm`,
|
||||
},
|
||||
zoology: {
|
||||
title: '生态',
|
||||
url: `${rootUrl}/zoology/index.htm`,
|
||||
},
|
||||
defense: {
|
||||
title: '国防',
|
||||
url: `${rootUrl}/defense/index.htm`,
|
||||
},
|
||||
international: {
|
||||
title: '国际',
|
||||
url: `${rootUrl}/international/index.htm`,
|
||||
},
|
||||
books: {
|
||||
title: '图书',
|
||||
url: `${rootUrl}/books/index.htm`,
|
||||
},
|
||||
xxbj: {
|
||||
title: '学习笔记',
|
||||
url: `${rootUrl}/qszq/xxbj/index.htm`,
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const category = ctx.params.category || 'toutiao';
|
||||
|
||||
const currentUrl = config[category].url;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('.list-style1 ul li a, .text h2 a, .no-pic ul li a')
|
||||
.slice(0, 15)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.text(),
|
||||
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('.fs-text, .fs-pinglun, .hidden-xs').remove();
|
||||
|
||||
item.author = content('.appellation').text();
|
||||
item.description = content('.highlight, .text').html() || content('.content').html();
|
||||
item.pubDate = new Date(content('.puttime_mobi, .pubtime, .headtitle span').text().replace('发表于', '').replace(/(年|月)/g, '-').replace('日', '')).toUTCString();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user