feat: add forums4399 (#5915)

* foums4399

* fix cookie

Co-authored-by: Henry Wang <hi@henry.wang>
This commit is contained in:
lwgpshit
2020-10-19 18:48:54 +08:00
committed by GitHub
parent 031bbc6c77
commit bcc27b3319
5 changed files with 65 additions and 0 deletions

View File

@@ -566,3 +566,7 @@ RSSHub 支持使用访问密钥 / 码,白名单和黑名单三种方式进行
- 喜马拉雅
- `XIMALAYA_TOKEN`: 对应 cookie 中的 `1&_token`获取方式1. 登陆喜马拉雅网页版 2. 查找名称为`1&_token``cookie`,其内容即为`XIMALAYA_TOKEN`的值(即在`cookie` 中查找 `1&_token=***;`,并设置 `XIMALAYA_TOKEN = ***`
- 4399 论坛
- `GAME_4399`: 对应登录后的 cookie 值获取方式1. 在 4399 首页登录. 2. 打开开发者工具,切换到 Network 面板. 3. 刷新 4. 查找`www.4399.com`的访问请求,点击请求,在右侧 Headers 中找到 Cookie.

View File

@@ -858,3 +858,13 @@ type 为 all 时category 参数不支持 cost 和 free
### はてな匿名ダイアリー - 人気記事アーカイブ
<Route author="masakichi" example="/hatena/anonymous_diary/archive" path="/hatena/anonymous_diary/archive"/>
### 4399 论坛
<Route author="DIYgod" example="/forum4399/mtag-83932" path="/forum4399/:mtag" :paramsDesc="['mtag,必选-论坛网址最后的mtag字段']"/>
::: warning 注意
需要用户 cookie 值,详情见部署页面的配置模块。
:::
</Route>

View File

@@ -167,6 +167,9 @@ const calculateValue = () => {
ximalaya: {
token: envs.XIMALAYA_TOKEN,
},
game4399: {
cookie: envs.GAME_4399,
},
};
};
calculateValue();

View File

@@ -3353,6 +3353,9 @@ router.get('/yuanshen/:location?/:category?', require('./routes/yuanshen/index')
// World Trade Organization
router.get('/wto/dispute-settlement/:year?', require('./routes/wto/dispute-settlement'));
// 4399论坛
router.get('/forum4399/:mtag', require('./routes/game4399/forum'));
// 国防科技大学
router.get('/nudt/yjszs/:id?', require('./routes/universities/nudt/yjszs'));

View File

@@ -0,0 +1,45 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const config = require('@/config').value;
module.exports = async (ctx) => {
const mtag = ctx.params.mtag;
const cookie = config.game4399.cookie;
const response = await got({
method: 'get',
url: `http://my.4399.com/forums/${mtag}`,
headers: {
Cookie: cookie,
},
});
const data = response.data;
const dex = cheerio.load(data);
const list = dex('li div.listtitle')
.map((index, item) => {
item = dex(item);
const author = item.parent().find('.author').text();
const link = 'http://my.4399.com' + item.parent().find('.thread_link').attr('href');
const title = item.parent().find('div.title').text() + ' ---------------最后回复->' + item.parent().find('.rtime span').text().trim() + ':' + item.parent().find('.rtime a').text().trim();
return {
title: title,
link: link,
author: author,
};
})
.get();
const items = await Promise.all(
list.map(async (item) => {
const res = await got({ method: 'get', url: item.link, headers: { Cookie: cookie } });
const content = cheerio.load(res.data);
content('div.host_content.j-thread-content img').not('.post_emoji').remove();
item.description = content('div.host_content.j-thread-content').html();
return item;
})
);
ctx.state.data = {
title: '论坛首页---4399',
link: 'http://my.4399.com/forums',
item: items,
};
};