mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-28 03:28:35 +08:00
fix(route): chinacerf (#9554)
* fix(route): chinacerf * Remove redundant `await`.
This commit is contained in:
+1
-1
@@ -239,7 +239,7 @@ pageClass: routes
|
||||
|
||||
## 首席经济学家论坛
|
||||
|
||||
### 最新更新文章列表
|
||||
### 最新更新
|
||||
|
||||
<Route author="FledgeXu" example="/chinacef" path="/chinacef"/>
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const response = await got(`http://www.chinacef.cn/index.php/experts/zjmain/experts_id/${ctx.params.experts_id}`);
|
||||
@@ -12,8 +10,6 @@ module.exports = async (ctx) => {
|
||||
const $ = cheerio.load(data);
|
||||
|
||||
const domArray = $('div[class^="leftnews"]');
|
||||
const itemAuthor = $('div[class=right515name] h3').text().trim();
|
||||
const siteLink = 'http://www.chinacef.cn';
|
||||
const rssTitle = $('title').text().trim();
|
||||
|
||||
const itemArray = await Promise.all(
|
||||
@@ -21,32 +17,22 @@ module.exports = async (ctx) => {
|
||||
.filter((index, item) => undefined !== $(item).find('h2 > a').attr('href'))
|
||||
.map(async (index, item) => {
|
||||
item = $(item);
|
||||
const itemLink = siteLink + item.find('h2 > a').attr('href');
|
||||
const detail = await ctx.cache.tryGet(itemLink, async () => {
|
||||
const result = await got.get(itemLink);
|
||||
const $ = cheerio.load(result.data);
|
||||
const description = art(path.join(__dirname, 'templates/work_description.art'), {
|
||||
desc: $('.newsmaintext').first().html().trim(),
|
||||
});
|
||||
return {
|
||||
title: $('.contenttitle').first().html().trim(),
|
||||
article: description,
|
||||
};
|
||||
});
|
||||
const itemLink = utils.siteLink + item.find('h2 > a').attr('href');
|
||||
const detail = await ctx.cache.tryGet(itemLink, async () => await utils.getArticleDetail(itemLink));
|
||||
|
||||
return {
|
||||
title: detail.title,
|
||||
description: detail.article,
|
||||
description: detail.description,
|
||||
link: itemLink,
|
||||
pubDate: parseDate(item.find('span').first().text(), 'YYYY-MM-DD'),
|
||||
author: itemAuthor,
|
||||
pubDate: detail.time,
|
||||
author: detail.author,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: rssTitle,
|
||||
link: siteLink,
|
||||
link: utils.siteLink,
|
||||
item: itemArray,
|
||||
};
|
||||
};
|
||||
|
||||
+6
-21
@@ -1,8 +1,6 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const utils = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const response = await got.get('http://www.chinacef.cn/index.php/index/index');
|
||||
@@ -12,33 +10,20 @@ module.exports = async (ctx) => {
|
||||
const $ = cheerio.load(data);
|
||||
|
||||
const domArray = $('#boardright ul');
|
||||
const siteLink = 'http://www.chinacef.cn';
|
||||
const rssTitle = '金融热点 - 首席经济学家论坛';
|
||||
|
||||
const itemArray = await Promise.all(
|
||||
domArray
|
||||
.map(async (index, item) => {
|
||||
item = $(item);
|
||||
const itemLink = siteLink + item.find('li a').attr('href');
|
||||
const detail = await ctx.cache.tryGet(itemLink, async () => {
|
||||
const result = await got.get(itemLink);
|
||||
const $ = cheerio.load(result.data);
|
||||
const description = art(path.join(__dirname, 'templates/work_description.art'), {
|
||||
desc: $('.newsmaintext').first().html().trim(),
|
||||
});
|
||||
return {
|
||||
title: $('.contenttitle').first().html().trim(),
|
||||
author: $('.zzinfo').find('h2').first().text().trim(),
|
||||
pubDate: parseDate($('.divwidth').text().trim().split(' ')[3], 'YYYY-MM-DD'),
|
||||
article: description,
|
||||
};
|
||||
});
|
||||
const itemLink = utils.siteLink + item.find('li a').attr('href');
|
||||
const detail = await ctx.cache.tryGet(itemLink, async () => await utils.getArticleDetail(itemLink));
|
||||
|
||||
return {
|
||||
title: detail.title,
|
||||
description: detail.article,
|
||||
description: detail.description,
|
||||
link: itemLink,
|
||||
pubDate: detail.pubDate,
|
||||
pubDate: detail.time,
|
||||
author: detail.author,
|
||||
};
|
||||
})
|
||||
@@ -47,7 +32,7 @@ module.exports = async (ctx) => {
|
||||
|
||||
ctx.state.data = {
|
||||
title: rssTitle,
|
||||
link: siteLink,
|
||||
link: utils.siteLink,
|
||||
item: itemArray,
|
||||
};
|
||||
};
|
||||
|
||||
+12
-40
@@ -1,17 +1,12 @@
|
||||
const utils = require('./utils');
|
||||
const cheerio = require('cheerio');
|
||||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const rootUrl = 'http://www.chinacef.cn';
|
||||
const rssTitle = '最新更新 - 首席经济学家论坛';
|
||||
const regex = /^\/index\.php\/index\/article\/article_id\/\d+/g;
|
||||
const timeRegex = /(\d{4}-\d{2}-\d{2})/g;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: rootUrl,
|
||||
});
|
||||
const response = await got.get('http://www.chinacef.cn/index.php/index/index');
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const articlesLinkListNode = $('a[target=_black]')
|
||||
@@ -19,39 +14,17 @@ module.exports = async (ctx) => {
|
||||
.map((_, item) => item.attribs.href);
|
||||
const articlesLinkList = Array.from(new Set(articlesLinkListNode));
|
||||
|
||||
const out = await Promise.all(
|
||||
const articles = await Promise.all(
|
||||
articlesLinkList.map(async (item) => {
|
||||
const articlesLink = rootUrl + item;
|
||||
const $ = await await ctx.cache.tryGet(articlesLink, async () => {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: articlesLink,
|
||||
});
|
||||
return cheerio.load(response.data);
|
||||
});
|
||||
const articlesLink = utils.siteLink + item;
|
||||
|
||||
// Clean article style
|
||||
$('*[style]').removeAttr('style');
|
||||
$('br').remove();
|
||||
$('span:empty').remove();
|
||||
$('p:empty').remove();
|
||||
$('p').each((_, el) => {
|
||||
if ($(el).html().trim() === '') {
|
||||
$(el).remove();
|
||||
}
|
||||
});
|
||||
|
||||
const title = $('span[class=contenttitle]').first().text().trim();
|
||||
const author = $('a[rel=author]').first().text().trim();
|
||||
const time = $('a[rel=author]').parent().text().match(timeRegex)[0];
|
||||
const pubDate = parseDate(time, 'YYYY-MM-DD');
|
||||
const description = $('div[class=newsmaintext]').html();
|
||||
const detail = await ctx.cache.tryGet(articlesLink, async () => await utils.getArticleDetail(articlesLink));
|
||||
|
||||
const element = {
|
||||
title,
|
||||
author,
|
||||
pubDate,
|
||||
description: utils.renderDesc(description),
|
||||
title: detail.title,
|
||||
author: detail.author,
|
||||
pubDate: detail.time,
|
||||
description: detail.description,
|
||||
link: articlesLink,
|
||||
};
|
||||
return element;
|
||||
@@ -59,9 +32,8 @@ module.exports = async (ctx) => {
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '首席经济学家论坛',
|
||||
description: '首席经济学家最近更新的文章',
|
||||
link: rootUrl,
|
||||
item: out,
|
||||
title: rssTitle,
|
||||
link: utils.siteLink,
|
||||
item: articles,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
<div>{{ desc }}</div>
|
||||
@@ -1,11 +1,55 @@
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
const cheerio = require('cheerio');
|
||||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const siteLink = 'http://www.chinacef.cn';
|
||||
|
||||
const renderDesc = (desc) =>
|
||||
art(path.join(__dirname, 'templates/description.art'), {
|
||||
desc,
|
||||
});
|
||||
|
||||
const cleanDom = (dom) => {
|
||||
dom('*[style]').removeAttr('style');
|
||||
dom('br').remove();
|
||||
dom('span:empty').remove();
|
||||
dom('p:empty').remove();
|
||||
dom('p').each((_, el) => {
|
||||
if (dom(el).html().trim() === '') {
|
||||
dom(el).remove();
|
||||
}
|
||||
});
|
||||
return dom;
|
||||
};
|
||||
|
||||
const getArticleDetail = async (link) => {
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
});
|
||||
const $ = cleanDom(cheerio.load(response.data));
|
||||
|
||||
const title = $('span[class=contenttitle]').first().text().trim();
|
||||
const author = $('a[rel=author]').first().text().trim();
|
||||
const time = parseDate($('.divwidth').text().trim().split(' ')[3], 'YYYY-MM-DD');
|
||||
const description = $('div[class=newsmaintext]').html();
|
||||
return new ArticleDetail(title, author, time, renderDesc(description));
|
||||
};
|
||||
class ArticleDetail {
|
||||
constructor(title, author, time, description) {
|
||||
this.title = title;
|
||||
this.author = author;
|
||||
this.time = time;
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
siteLink,
|
||||
renderDesc,
|
||||
cleanDom,
|
||||
getArticleDetail,
|
||||
ArticleDetail,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user