fix: add descriptions of rules in szes (#5563)

This commit is contained in:
Ethan Shen 2020-09-02 20:47:56 +08:00 committed by GitHub
parent 92ab0efacf
commit 29f2e73d70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 3 deletions

View File

@ -1,4 +1,3 @@
const url = require('url');
const got = require('@/utils/got');
const cheerio = require('cheerio');
@ -16,15 +15,32 @@ module.exports = async (ctx) => {
const s = item.find('script').html();
return {
title: s.match(/var curTitle ='(.*?)';/)[1],
link: url.resolve(`http://www.szse.cn/lawrules/rule`, s.match(/var curHref = '..(.*?)';/)[1]),
link: `http://www.szse.cn/lawrules/rule${s.match(/var curHref = '..(.*?)';/)[1]}`,
pubDate: new Date(item.find('span.time').text().trim()).toUTCString(),
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
item.description = content('#desContent').html();
return item;
})
)
);
ctx.state.data = {
title: '深圳证券交易所 - 最新规则',
link: currentUrl,
item: list,
item: items,
};
};