From 9535fe83d2303e8ab23c765315bd3232772abdef Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Wed, 21 Oct 2020 22:57:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20The=20Economist=20=E7=BB=8F?= =?UTF-8?q?=E6=B5=8E=E5=AD=A6=E4=BA=BA=E4=B8=8B=E8=BD=BD=20(#5964)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/traditional-media.md | 9 +++++++++ docs/traditional-media.md | 8 ++++++++ lib/router.js | 1 + lib/routes/the-economist/download.js | 30 ++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 lib/routes/the-economist/download.js diff --git a/docs/en/traditional-media.md b/docs/en/traditional-media.md index 5693dee1f..fd310fad0 100644 --- a/docs/en/traditional-media.md +++ b/docs/en/traditional-media.md @@ -162,6 +162,7 @@ This route adds the missing photo and Link element. (Offical RSS doesn't have Li See the [official RSS page](https://www.scmp.com/rss) to get the ID of each category. This route provides fulltext that the offical feed doesn't. + ## The Economist ### Category @@ -172,6 +173,14 @@ See the [official RSS page](https://www.scmp.com/rss) to get the ID of each cate +### Download + + + +The download site: http://www.cgx02.xyz/index.php?dir=/te + + + ## The Guardian ### Editorial diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 65a07f99d..a75e2a88a 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -177,6 +177,14 @@ Solidot 提供的 feed: +### 下载 + + + +下载站: + + + ## Yahoo ### 新聞 diff --git a/lib/router.js b/lib/router.js index 488e1e9a1..72dda85b4 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1621,6 +1621,7 @@ router.get('/gradcafe/result/:type', require('./routes/gradcafe/result')); router.get('/gradcafe/result', require('./routes/gradcafe/result')); // The Economist +router.get('/the-economist/download', require('./routes/the-economist/download')); router.get('/the-economist/gre-vocabulary', require('./routes/the-economist/gre-vocabulary')); router.get('/the-economist/:endpoint', require('./routes/the-economist/full')); diff --git a/lib/routes/the-economist/download.js b/lib/routes/the-economist/download.js new file mode 100644 index 000000000..0cb443304 --- /dev/null +++ b/lib/routes/the-economist/download.js @@ -0,0 +1,30 @@ +const url = require('url'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const link = 'http://www.cgx02.xyz/index.php?dir=/te'; + +module.exports = async (ctx) => { + const response = await got({ + method: 'get', + url: link, + }); + + const $ = cheerio.load(response.data); + const items = $('tbody tr').not('#id1').not('#id2').not('#id3').get(); + + ctx.state.data = { + title: '经济学人 the Economist', + link: link, + item: items.map((item) => { + item = $(item); + const one = item.find('td').eq(0); + return { + title: one.find('a').text(), + link: url.resolve('http://www.cgx02.xyz/', one.find('a').attr('href')), + pubDate: new Date(item.find('td.layui-hide-xs').eq(1).text()).toUTCString(), + enclosure_url: item.link, + }; + }), + }; +};