feat: add 它惠网线报列表 (#5533)

Co-authored-by: Henry Wang <hi@henry.wang>
This commit is contained in:
Ethan Shen
2020-08-29 05:04:09 +08:00
committed by GitHub
parent d80582d392
commit ea5428e12b
3 changed files with 58 additions and 0 deletions

View File

@@ -209,6 +209,12 @@ For instance, in <https://www.leboncoin.fr/recherche/?**category=10&locations=Pa
<Route author="nczitzk" example="/smzdm/baoliao/7367111021" path="/smzdm/baoliao/:uid" :paramsDesc="['用户id网址上直接可以看到']"/>
## 它惠网
### 线报
<Route author="nczitzk" example="/tahui/rptlist" path="/tahui/rptlist"/>
## 淘宝众筹
### 众筹项目

View File

@@ -3119,6 +3119,9 @@ router.get('/fjnews/fz/30', require('./routes/fjnews/fznews'));
// 九江新闻jjnews
router.get('/fjnews/jjnews', require('./routes/fjnews/jjnews'));
// 它惠网
router.get('/tahui/rptlist', require('./routes/tahui/rptlist'));
// Guiltfree
router.get('/guiltfree/onsale', require('./routes/guiltfree/onsale'));

View File

@@ -0,0 +1,49 @@
const url = require('url');
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const rootUrl = 'https://www.tahui.com/';
const currentUrl = 'https://www.tahui.com/rptlist';
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const list = $('article.excerpt h2')
.slice(0, 10)
.map((_, item) => {
item = $(item);
const a = item.find('a').eq(0);
return {
title: a.text(),
link: url.resolve(rootUrl, a.attr('href')),
};
})
.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.pubDate = new Date(content('div.meta span').eq(0).text().trim().replace(/\n/g, '')).toUTCString();
item.description = content('div.artcontent').html();
return item;
})
)
);
ctx.state.data = {
title: '它惠网 - 线报',
link: currentUrl,
item: items,
};
};