feat(route): 19楼头条 (#9963)

* feat(route): 19楼头条

* fix: new setCookie
This commit is contained in:
Ethan Shen
2022-06-18 00:56:51 +00:00
committed by GitHub
parent 9402a65d73
commit e6ab7dde96
5 changed files with 133 additions and 0 deletions
+24
View File
@@ -4,6 +4,30 @@ pageClass: routes
# 论坛
## 19 楼
### 头条
<Route author="nczitzk" example="/19lou/jiaxing" path="/19lou/:city?" :paramsDesc="['分类,见下表,默认为 www,即杭州']">
| 杭州 | 台州 | 嘉兴 | 宁波 | 湖州 |
| --- | ------- | ------- | ------ | ------ |
| www | taizhou | jiaxing | ningbo | huzhou |
| 绍兴 | 湖州 | 温州 | 金华 | 舟山 |
| -------- | ------ | ------- | ------ | -------- |
| shaoxing | huzhou | wenzhou | jinhua | zhoushan |
| 衢州 | 丽水 | 义乌 | 萧山 | 余杭 |
| ------ | ------ | ---- | -------- | ------ |
| quzhou | lishui | yiwu | xiaoshan | yuhang |
| 临安 | 富阳 | 桐庐 | 建德 | 淳安 |
| ----- | ------ | ------ | ------ | ------ |
| linan | fuyang | tonglu | jiande | chunan |
</Route>
## 2047
### 分类
+74
View File
@@ -0,0 +1,74 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const iconv = require('iconv-lite');
const setCookie = function (cookieName, cookieValue, seconds, path, domain, secure) {
let expires = null;
if (seconds !== -1) {
expires = new Date();
expires.setTime(expires.getTime() + seconds);
}
return [encodeURI(cookieName), '=', encodeURI(cookieValue), expires ? '; expires=' + expires.toGMTString() : '', path ? '; path=' + path : '/', domain ? '; domain=' + domain : '', secure ? '; secure' : ''].join('');
};
module.exports = async (ctx) => {
const city = ctx.params.city ?? 'www';
const rootUrl = `https://${city}.19lou.com`;
const response = await got({
method: 'get',
url: rootUrl,
responseType: 'buffer',
});
const $ = cheerio.load(iconv.decode(response.data, 'gbk'));
$('.title-more').remove();
let items = $('.center-center-jiazi')
.find('a[title]')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.attr('title'),
link: `https:${item.attr('href')}`,
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
responseType: 'buffer',
headers: {
cookie: setCookie('_Z3nY0d4C_', '37XgPK9h', 365, '/', '19lou.com'),
referer: rootUrl,
},
});
const content = cheerio.load(iconv.decode(detailResponse.data, 'gbk'));
content('.name-lz, .postView-pk-mod').remove();
item.author = content('.uname, .user-name').first().text();
item.description = content('.post-cont').first().html() || content('.thread-cont').html();
item.pubDate = timezone(parseDate(content('.cont-top-left meta').first().attr('content')), +8);
return item;
})
)
);
ctx.state.data = {
title: $('title').text().split('-')[0],
link: rootUrl,
item: items,
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/:city?': ['nczitzk'],
};
+29
View File
@@ -0,0 +1,29 @@
module.exports = {
'19lou.com': {
_name: '19 楼',
'.': [
{
title: '头条',
docs: 'https://docs.rsshub.app/bbs.html#19-lou-tou-tiao',
source: ['/'],
target: (params, url) => `/19lou/${new URL(url).toString().match(/\/\/(.*?)\.19lou/)[1]}`,
},
],
www: [
{
title: '头条',
docs: 'https://docs.rsshub.app/bbs.html#19-lou-tou-tiao',
source: ['/'],
target: '/19lou/www',
},
],
jiaxing: [
{
title: '头条',
docs: 'https://docs.rsshub.app/bbs.html#19-lou-tou-tiao',
source: ['/'],
target: '/19lou/jiaxing',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/:city?', require('./index'));
};