diff --git a/docs/other.md b/docs/other.md index 2732fb6df7..03634b0567 100644 --- a/docs/other.md +++ b/docs/other.md @@ -928,6 +928,17 @@ type 为 all 时,category 参数不支持 cost 和 free +## 万联网 + +### 资讯 + + + +| 全部 | 天下大势 | 企业动态 | 专家观点 | 研究报告 | +| ---- | -------- | -------- | -------- | -------- | +| (空) | My01 | My02 | My03 | My04 | + + ## 维基百科 ### 中国大陆新闻动态 diff --git a/lib/router.js b/lib/router.js index 2f32d6e440..f7c76a152b 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1556,6 +1556,9 @@ router.get('/wikihow/category/:category/:type', require('./routes/wikihow/catego router.get('/getitfree/category/:category?', require('./routes/getitfree/category.js')); router.get('/getitfree/search/:keyword?', require('./routes/getitfree/search.js')); +// 万联网 +router.get('/10000link/news/:category?', require('./routes/10000link/news')); + // Artand router.get('/artand/user/work/:uid', require('./routes/artand/user/work')); diff --git a/lib/routes/10000link/news.js b/lib/routes/10000link/news.js new file mode 100644 index 0000000000..470e345d59 --- /dev/null +++ b/lib/routes/10000link/news.js @@ -0,0 +1,64 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const url = require('url'); +const { addNoReferrer } = require('@/utils/common-utils'); + +module.exports = async (ctx) => { + const category = ctx.params.category; + const pageUrl = `http://info.10000link.com/newslists.aspx?chid=${category}`; + const host = 'http://info.10000link.com'; + const response = await got({ + method: 'get', + url: pageUrl, + }); + const $ = cheerio.load(response.data); + const list = $('.l_newshot li').get(); + + const ProcessFeed = async (link) => { + const response = await got({ + method: 'get', + url: link, + }); + + const $ = cheerio.load(response.data); + + addNoReferrer($, '#news_body'); + + return $('#news_body').html(); + }; + + const items = await Promise.all( + list.map(async (item) => { + const $ = cheerio.load(item); + const $a = $('h1 a'); + const link = url.resolve(host, $a.attr('href')); + + const cache = await ctx.cache.get(link); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const description = await ProcessFeed(link); + + const single = { + title: $a.text(), + description, + link: link, + pubDate: new Date($('.ymd_w').text()).toUTCString(), + author: $('.day-lx span:first-child').text(), + }; + + ctx.cache.set(link, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: `万联网 ${$('.t-h2') + .text() + .replace(' |资讯频道', '')}`, + link: pageUrl, + description: $('meta[name="Description"]').attr('content'), + item: items, + }; +};