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, + }; +};