feat: add 日本経済新聞 (#5855)
Co-authored-by: codefactor-io <support@codefactor.io>
This commit is contained in:
@@ -257,9 +257,9 @@ Category 列表:
|
||||
|
||||
### 新聞
|
||||
|
||||
<Route author="Arracc" example="/yomiuri/news" path="/yomiuri/:category" :paramsDesc="['分类']">
|
||||
<Route author="Arracc" example="/yomiuri/news" path="/yomiuri/:category" :paramsDesc="['板块']">
|
||||
|
||||
无料全文,综合页添加分类标签,可用于过滤。
|
||||
无料全文,综合页文章标题添加板块标签。
|
||||
|
||||
| 総合 | 社会 | 政治 | 経済 | スポーツ | 国際 | 科学・IT | 選挙・世論調査 | エンタメ・文化 | 囲碁・将棋 | ライフ | 地域 | 社説 |
|
||||
| ---- | -------- | -------- | ------- | -------- | ----- | ---------- | -------------- | -------------- | ---------- | ------ | ----- | --------- |
|
||||
@@ -587,6 +587,18 @@ category 对应的关键词有
|
||||
|
||||
</Route>
|
||||
|
||||
### 新聞
|
||||
|
||||
<Route author="Arracc" example="/nikkei/news" path="/nikkei/:category/:article_type?" :paramsDesc="['版块','文章类型,free仅无料全文,缺省为无料全文、有料非全文']">
|
||||
|
||||
综合页文章标题添加板块标签
|
||||
|
||||
| 総合 | マネーのまなび | 経済・金融 | 政治 | ビジネス | マネーのまなび | テクノロジー | 国際 | スポーツ | 社会・くらし | オピニオン | 文化 | FT | 地域 | 日経ビジネス | ライフ |
|
||||
| ---- | -------------- | ---------- | -------- | -------- | -------------- | ------------ | ------------- | -------- | ------------ | ---------- | ------- | ------ | ----- | ------------ | ------ |
|
||||
| news | 未支持 | economy | politics | business | 未支持 | technology | international | sports | society | opinion | culture | 未支持 | local | 未支持 | 未支持 |
|
||||
|
||||
</Route>
|
||||
|
||||
## 台湾中央通讯社
|
||||
|
||||
### 分类
|
||||
|
||||
@@ -2461,6 +2461,7 @@ router.get('/njfu/jwc/:category?', require('./routes/universities/njfu/jwc'));
|
||||
|
||||
// 日本経済新聞
|
||||
router.get('/nikkei/index', require('./routes/nikkei/index'));
|
||||
router.get('/nikkei/:category/:article_type?', require('./routes/nikkei/news'));
|
||||
|
||||
// MQube
|
||||
router.get('/mqube/user/:user', require('./routes/mqube/user'));
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const category = ctx.params.category;
|
||||
const article_type = ctx.params.article_type;
|
||||
let url = '';
|
||||
if (category === 'news') {
|
||||
url = `https://www.nikkei.com`;
|
||||
} else {
|
||||
url = `https://www.nikkei.com/${category}/archive`;
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: url,
|
||||
});
|
||||
const data = response.data;
|
||||
const $ = cheerio.load(data);
|
||||
|
||||
let categoryName = '';
|
||||
let list = null;
|
||||
let iconElement = '';
|
||||
if (category === 'news') {
|
||||
categoryName = '総合';
|
||||
list = $('div.k-card.k-card--small.k-card--reverse,.k-card--headline').not('[data-rn-track="hub-ad-recommend"]').not('.k-hub-card--small-title');
|
||||
iconElement = 'li.k-card__icon';
|
||||
} else {
|
||||
categoryName = $('h1.l-miH11_title').text().trim();
|
||||
list = $('div#CONTENTS_MAIN').children('div.m-miM09').not('.PRa');
|
||||
iconElement = 'span.m-iconMember';
|
||||
}
|
||||
|
||||
const deleteItems = [];
|
||||
const items = await Promise.all(
|
||||
list
|
||||
.map(async (index, item) => {
|
||||
item = $(item);
|
||||
let title = '';
|
||||
let link = '';
|
||||
const memberLimit = item.find(iconElement).length > 0;
|
||||
|
||||
if (memberLimit && article_type === 'free') {
|
||||
deleteItems.push(title);
|
||||
return {
|
||||
title,
|
||||
description: '',
|
||||
link,
|
||||
};
|
||||
} else {
|
||||
if (category === 'news') {
|
||||
title = item.find('a').eq(0).text();
|
||||
link = item.find('a.k-card__block-link').eq(0).attr('href');
|
||||
} else {
|
||||
title = item.children('h3').children('a').text();
|
||||
link = item.find('a').eq(0).attr('href');
|
||||
}
|
||||
if (link.substring(0, 4) !== 'http') {
|
||||
link = 'https://www.nikkei.com' + link;
|
||||
}
|
||||
|
||||
const tagArr = [];
|
||||
if (categoryName === '総合') {
|
||||
const tagTable = {
|
||||
economy: '経済・金融',
|
||||
politics: '政治',
|
||||
business: 'ビジネス',
|
||||
technology: 'テクノロジー',
|
||||
international: '国際',
|
||||
sports: 'スポーツ',
|
||||
society: '社会・くらし',
|
||||
opinion: 'オピニオン',
|
||||
culture: '文化',
|
||||
local: '地域',
|
||||
style: 'ライフ',
|
||||
};
|
||||
item.find('li.k-card__tag')
|
||||
.children()
|
||||
.each((index, item) => {
|
||||
const tagPath = $(item).attr('href');
|
||||
let tag = '';
|
||||
if (tagPath.indexOf('?dw') >= 0) {
|
||||
tag = $('a[href="https://www.nikkei.com' + tagPath.replace('?', '/?') + '"]')
|
||||
.parent()
|
||||
.parent()
|
||||
.parent()
|
||||
.parent()
|
||||
.parent()
|
||||
.children('a')
|
||||
.text();
|
||||
} else if (tagPath.indexOf('style') >= 0) {
|
||||
tag = 'ライフ';
|
||||
} else {
|
||||
tag = tagTable[tagPath.split('/')[1]];
|
||||
}
|
||||
tag = tag ? tag : 'コラム';
|
||||
if (tag !== 'トップ' && tagArr.indexOf(tag) < 0) {
|
||||
tagArr.push(tag);
|
||||
}
|
||||
});
|
||||
const start = tagArr.indexOf('コラム');
|
||||
if (start >= 0 && tagArr.length > 1) {
|
||||
tagArr.splice(start, 1);
|
||||
}
|
||||
}
|
||||
if (memberLimit) {
|
||||
tagArr.push('会員限定');
|
||||
}
|
||||
if (tagArr.length > 0) {
|
||||
title = '[' + tagArr.join(' ') + '] ' + title;
|
||||
}
|
||||
|
||||
const description = await ctx.cache.tryGet(link, async () => {
|
||||
const response = await got.get(link);
|
||||
const $ = cheerio.load(response.data);
|
||||
return $('div.cmn-article_text.a-cf.JSID_key_fonttxt.m-streamer_medium').html();
|
||||
});
|
||||
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
link,
|
||||
};
|
||||
}
|
||||
})
|
||||
.get()
|
||||
);
|
||||
|
||||
for (const deleteItem of deleteItems) {
|
||||
for (let index = 0; index < items.length; index++) {
|
||||
const item = items[index];
|
||||
if (item.title === deleteItem) {
|
||||
items.splice(index, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ctx.state.data = {
|
||||
title: '日本経済新聞-' + categoryName,
|
||||
link: url,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user