fix(route): 新华社新闻 (#8559)
This commit is contained in:
parent
ceaff4c420
commit
884520931c
|
|
@ -3958,7 +3958,7 @@ router.get('/tianyancha/hot', lazyloadRouteHandler('./routes/tianyancha/hot'));
|
|||
router.get('/kingarthur/:type', lazyloadRouteHandler('./routes/kingarthur/index'));
|
||||
|
||||
// 新华网
|
||||
router.get('/news/whxw', lazyloadRouteHandler('./routes/news/whxw'));
|
||||
// router.get('/news/whxw', lazyloadRouteHandler('./routes/news/whxw'));
|
||||
|
||||
// 游讯网
|
||||
router.get('/yxdown/recommend', lazyloadRouteHandler('./routes/yxdown/recommend'));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/whxw': ['nczitzk'],
|
||||
};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
'news.cn': {
|
||||
_name: '新华网',
|
||||
'.': [
|
||||
{
|
||||
title: '新华社新闻',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#xin-hua-wang-xin-hua-she-xin-wen',
|
||||
source: ['/'],
|
||||
target: '/news/whxw',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function (router) {
|
||||
router.get('/whxw', require('./whxw'));
|
||||
};
|
||||
|
|
@ -13,39 +13,47 @@ module.exports = async (ctx) => {
|
|||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('h3 a')
|
||||
.slice(0, 35)
|
||||
.map((_, item) => {
|
||||
let items = $('h3 a')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.text(),
|
||||
link: item.attr('href'),
|
||||
};
|
||||
})
|
||||
.get();
|
||||
});
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
let detailResponse;
|
||||
|
||||
try {
|
||||
detailResponse = await got(item.link);
|
||||
} catch (error) {
|
||||
item.status = 404;
|
||||
}
|
||||
|
||||
if (item.status !== 404) {
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
const date = content('.header-time.left').text();
|
||||
const author =
|
||||
content('.editor').text() ||
|
||||
content('.editor').text() ??
|
||||
content('.p-jc')
|
||||
.text()
|
||||
.replace(/[\r\n]/g, '');
|
||||
item.author = author.match(/责任编辑.(.*)/)[1].trim();
|
||||
.replace(/[\r\n]/g, '')
|
||||
.replace(': ', ':')
|
||||
.trim();
|
||||
|
||||
item.author = author.split(':').pop().replace('】', '');
|
||||
|
||||
content('#articleEdit').remove();
|
||||
|
||||
item.description = content('#detail').html();
|
||||
item.pubDate = timezone(parseDate(date, 'YYYYMM/DD HH:mm:ss'), +8);
|
||||
}
|
||||
|
||||
delete item.status;
|
||||
return item;
|
||||
})
|
||||
)
|
||||
Loading…
Reference in New Issue