fix(route): fix gamer anti crawl (#8678)

This commit is contained in:
Tony 2022-01-23 03:02:01 +07:00 committed by GitHub
parent c2fdbb5df1
commit b1a20c3a17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 6 deletions

View File

@ -3393,8 +3393,8 @@ router.get('/appsales/:caty?/:time?', lazyloadRouteHandler('./routes/appsales/in
// Academy of Management
router.get('/aom/journal/:id', lazyloadRouteHandler('./routes/aom/journal'));
// 巴哈姆特電玩資訊站
router.get('/gamer/hot/:bsn', lazyloadRouteHandler('./routes/gamer/hot'));
// 巴哈姆特電玩資訊站 migrated to v2
// router.get('/gamer/hot/:bsn', lazyloadRouteHandler('./routes/gamer/hot'));
// iCity
router.get('/icity/:id', lazyloadRouteHandler('./routes/icity/index'));

View File

@ -1,16 +1,19 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
module.exports = async (ctx) => {
const rootUrl = `https://forum.gamer.com.tw/A.php?bsn=${ctx.params.bsn}`;
const response = await got({
method: 'get',
url: rootUrl,
header: {
Referer: 'https://forum.gamer.com.tw',
},
});
const $ = cheerio.load(response.data);
const list = $('div.FM-abox2A a.FM-abox2B')
.slice(0, 10)
.map((_, item) => {
item = $(item);
return {
@ -23,8 +26,10 @@ module.exports = async (ctx) => {
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
headers: {
Referer: rootUrl,
},
});
const content = cheerio.load(detailResponse.data);
@ -33,7 +38,7 @@ module.exports = async (ctx) => {
item.title = content('.c-post__header__title').text();
item.description = content('div.c-post__body').html();
item.author = `${content('a.username').eq(0).text()} (${content('a.userid').eq(0).text()})`;
item.pubDate = new Date(content('a.edittime').eq(0).attr('data-mtime') + ' GMT+8').toUTCString();
item.pubDate = timezone(parseDate(content('a.edittime').eq(0).attr('data-mtime'), +8));
return item;
})
@ -45,4 +50,10 @@ module.exports = async (ctx) => {
link: rootUrl,
item: items,
};
ctx.state.json = {
title: $('title').text(),
link: rootUrl,
item: items,
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/hot/:bsn': ['nczitzk', 'TonyRL'],
};

13
lib/v2/gamer/radar.js Normal file
View File

@ -0,0 +1,13 @@
module.exports = {
'gamer.com.tw': {
_name: '巴哈姆特電玩資訊站',
forum: [
{
title: '熱門推薦',
docs: 'https://docs.rsshub.app/bbs.html#ba-ha-mu-te-dian-wan-zi-xun-zhan',
source: ['/A.php', '/B.php'],
target: (params, url) => `/gamer/hot/${new URL(url).searchParams.get('bsn')}`,
},
],
},
};

3
lib/v2/gamer/router.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = function (router) {
router.get('/hot/:bsn', require('./hot'));
};