From 6586f09907cd3e73f1bb68271ac97147ef3a2985 Mon Sep 17 00:00:00 2001 From: Jeason0228 <44083849+Jeason0228@users.noreply.github.com> Date: Mon, 30 Sep 2019 15:08:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=AF=B9=E3=80=90?= =?UTF-8?q?=E6=B7=B1=E5=9C=B3=E8=AF=81=E5=88=B8=E4=BA=A4=E6=98=93=E6=89=80?= =?UTF-8?q?-=E4=B8=8A=E5=B8=82=E5=85=AC=E5=91=8A-=E5=8F=AF=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E5=80=BA=E5=88=B8=E3=80=91=E7=9A=84=E6=94=AF=E6=8C=81?= =?UTF-8?q?=20(#3171)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/other.md | 6 +++ lib/router.js | 3 ++ lib/routes/szse/notice.js | 86 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 lib/routes/szse/notice.js diff --git a/docs/other.md b/docs/other.md index 910f17138..f0bd1b4a5 100644 --- a/docs/other.md +++ b/docs/other.md @@ -289,6 +289,12 @@ type 为 all 时,category 参数不支持 cost 和 free +## 深圳证券交易所 + +### 上市公告-可转换债券 + + + ## 搜狗 ### 搜狗特色 LOGO diff --git a/lib/router.js b/lib/router.js index 3285bc5e4..2676c8d89 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1692,6 +1692,9 @@ router.get('/latexstudio/home', require('./routes/latexstudio/home')); // 上证债券信息网 - 可转换公司债券公告 router.get('/sse/convert/:query?', require('./routes/sse/convert')); +// 深圳证券交易所——上市公告 +router.get('/szse/notice/', require('./routes/szse/notice')); + // 前端艺术家每日整理&&飞冰早报 router.get('/jskou/:type?', require('./routes/jskou/index')); diff --git a/lib/routes/szse/notice.js b/lib/routes/szse/notice.js new file mode 100644 index 000000000..face6420a --- /dev/null +++ b/lib/routes/szse/notice.js @@ -0,0 +1,86 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const url = require('url'); +const host = 'http://www.szse.cn/'; +module.exports = async (ctx) => { + const link = 'http://www.szse.cn/disclosure/notice/company/index.html'; + const response = await got.get(link, { + Referer: host, + }); + const $ = cheerio.load(response.data); + // 正则表达式匹配Script标签的url和title变量 + function getData(jscontent, option) { + // eslint-disable-next-line + const urlpattern = /(?<=curHref \= \'\.\/).*?(?=\'\;)/; + // eslint-disable-next-line + const titlepattern = /(?<=curTitle \=\').*?(?=\'\;)/; + + switch (option) { + case 'title': { + const jsoutput = jscontent.match(titlepattern); + return jsoutput; + } + case 'url': { + const jsoutput = jscontent.match(urlpattern); + return jsoutput; + } + default: { + // console.log('default'); + break; + } + } + } + + const list = $('.article-list .newslist li') + .map(function() { + const info = { + title: getData( + $(this) + .find('script') + .html(), + 'title' + ), + link: `http://www.szse.cn/disclosure/notice/company/${getData( + $(this) + .find('script') + .html(), + 'url' + )}`, + date: $(this) + .find('span.time') + .text() + .trim(), // trim移除多余的空格 + }; + return info; + }) + .get(); + const out = await Promise.all( + list.map(async (info) => { + const title = info.title; + const date = info.date; + const itemUrl = url.resolve(host, info.link); + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + const response = await got.get(itemUrl, { + Referer: host, + }); + const $ = cheerio.load(response.data); + const description = $('#desContent').html(); + const single = { + title: title, + link: itemUrl, + description: description, + pubDate: new Date(date).toDateString(), + }; + ctx.cache.set(itemUrl, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + ctx.state.data = { + title: '深圳证券交易所——上市公告-可转换债券', + link: link, + item: out, + }; +};