feat: add wineyun site && nbd news (#3197)

This commit is contained in:
Xunco
2019-10-09 11:25:23 +08:00
committed by DIYgod
parent 4a7693fab6
commit b12d339178
6 changed files with 204 additions and 0 deletions
+11
View File
@@ -535,4 +535,15 @@
},
],
},
'wineyun.com': {
_name: '酒云网',
www: [
{
title: '最新商品',
description: 'https://docs.rsshub.app/other.html#jiu-yun-wang',
source: ['/:category'],
target: '/wineyun/:category',
},
],
},
});
+11
View File
@@ -187,3 +187,14 @@ pageClass: routes
### 商品上新
<Route author="LogicJake" example="/youzan/goods/13328377" path="/youzan/goods/:id" :paramsDesc="['商铺id']"/>
## 酒云网
### 最新商品
<Route author="MeXunco" example="/wineyun/home" path="/wineyun/:category" :paramsDesc="['分类名']" >
| 全部 | 闪购 | 秒发 | 跨境 |
| -------- | ------- | --- | ------- |
| home | shangou | miaofa | csborder |
</Route>
+6
View File
@@ -228,6 +228,12 @@ category 对应的关键词有
</Route>
## 每经网
### 重磅原创
<Route author="MeXunco" example="/nbd/daily" path="/nbd/daily" />
## 南方周末
### 新闻分类
+6
View File
@@ -1793,6 +1793,12 @@ router.get('/watchface/:watch_type?/:list_type?', require('./routes/watchface/up
router.get('/cnu/selected', require('./routes/cnu/selected'));
router.get('/cnu/discovery/:type?/:category?', require('./routes/cnu/discovery'));
// 酒云网
router.get('/wineyun/:category', require('./routes/wineyun'));
// 重磅原创-每经网
router.get('/nbd/daily', require('./routes/nbd/article'));
// 快知
router.get('/kzfeed/topic/:id', require('./routes/kzfeed/topic'));
+72
View File
@@ -0,0 +1,72 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
module.exports = async (ctx) => {
const url = 'http://www.nbd.com.cn/columns/332';
const response = await got({
method: 'get',
url: url,
headers: {
Referer: 'http://www.nbd.com.cn',
},
});
const $ = cheerio.load(response.data);
const $list = $('li.u-news-title')
.slice(0, 15)
.get();
const description = $('head title')
.text()
.trim();
const resultItem = await Promise.all(
$list.map(async (item) => {
const title = $(item)
.find('a')
.text()
.trim();
const pubDate = $(item)
.find('span')
.text()
.trim();
const itemUrl = $(item)
.find('a')
.attr('href');
const single = {
title: title,
link: itemUrl,
pubDate: pubDate,
description: '',
};
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const detail = await got({
method: 'get',
url: itemUrl,
headers: {
Referer: 'http://www.nbd.com.cn',
},
});
{
const $ = cheerio.load(detail.data);
single.description = $('div.g-article').html();
}
ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: '重磅原创-每经网',
link: url,
item: resultItem,
description: description,
};
};
+98
View File
@@ -0,0 +1,98 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const category = ctx.params.category;
const url = 'http://www.wineyun.com/' + category;
const flag = category === 'csborder';
const response = await got({
method: 'get',
url: url,
headers: {
Referer: 'http://www.wineyun.com',
},
});
const $ = cheerio.load(response.data);
const $list = !flag
? $('div.groupinfo')
.slice(0, 10)
.get()
: $('div a.topitem')
.slice(0, 10)
.get();
const description = $('head title');
const resultItem = await Promise.all(
$list.map(async (item) => {
const title = !flag
? $(item)
.find('h1.bti')
.text()
.trim()
: $(item).attr('title');
const itemPicUrl = !flag
? $(item)
.find('div.fl img')
.attr('src')
: $(item)
.find('div.fl img')
.attr('src');
const href = !flag
? $(item)
.find('dt.fl a')
.attr('href')
: $(item).attr('href');
const price = !flag
? $(item)
.find('dt.fl a i.fl')
.text()
.trim()
: $(item)
.find('span.price')
.text()
.trim();
const itemDetailurl = 'http://www.wineyun.com' + href;
const cache = await ctx.cache.get(itemDetailurl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const single = {
title: `${price} ${title}`,
link: itemDetailurl,
description: '',
};
const detail = await got({
method: 'get',
url: itemDetailurl,
headers: {
Referer: 'http://www.wineyun.com',
},
});
{
const detailData = detail.data;
const $ = cheerio.load(detailData);
$('div#htmlDetails p img').replaceWith('');
single.description = `<img src ="${itemPicUrl}"><br>` + $('div#htmlDetails').html();
}
ctx.cache.set(itemDetailurl, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: '酒云网-最新商品',
link: url,
item: resultItem,
description: description,
};
};