diff --git a/docs/shopping.md b/docs/shopping.md index d979b08d2d..1a9403887d 100644 --- a/docs/shopping.md +++ b/docs/shopping.md @@ -209,6 +209,12 @@ For instance, in +## 它惠网 + +### 线报 + + + ## 淘宝众筹 ### 众筹项目 diff --git a/lib/router.js b/lib/router.js index 334ac887ab..f52040d541 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/tahui/rptlist.js b/lib/routes/tahui/rptlist.js new file mode 100644 index 0000000000..6073cd9611 --- /dev/null +++ b/lib/routes/tahui/rptlist.js @@ -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, + }; +};