fix(route): /gamer/gnn original page elements changed (#7864)

This commit is contained in:
Arracc
2021-07-17 02:12:15 -07:00
committed by GitHub
parent b023b6034e
commit b008df1244
+46 -33
View File
@@ -1,5 +1,7 @@
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 category = ctx.params.category;
@@ -47,37 +49,25 @@ module.exports = async (ctx) => {
const list = $('div.BH-lbox.GN-lbox2')
.children()
.not('.GN-lbox2A,.GN-lbox2G')
.not('p,a,img,span')
.map((index, item) => {
item = $(item);
const position = item.attr('class') === 'GN-lbox2F' ? 0 : 1;
const ElementA = item.find('a').eq(position);
const tagTable = {
'IMG-Gmuti': 'General',
'IMG-GA19': 'PC',
'IMG-GB3': 'NS',
'IMG-GB4': 'PS5',
'IMG-GB1': 'PS4',
'IMG-GB2': 'xone',
'IMG-GB5': 'Xbox',
'IMG-GA14': 'ARC',
'IMG-GAC': 'AC',
'IMG-GA13': 'ETC',
'IMG-GA1': 'OLG',
'IMG-Gmobi': 'MOBI',
'IMG-GA20': 'WEB',
'IMG-GA25': 'Google',
'IMG-GA24': 'Apple',
'IMG-GA28': 'Facebook',
'IMG-GA17': 'Other',
'IMG-GA23': 'Other',
'IMG-Gother': 'Other',
};
const tagValue = tagTable[item.find('img').eq(position).attr('class')];
const tag = tagValue ? tagValue : 'Unclassified';
let aLabelNode;
let tag;
// a label with div
if (item.children().length !== 0) {
aLabelNode = item.find('a').eq(1);
tag = item.find('div.platform-tag_list').text();
}
// a label without div
else {
aLabelNode = item.next();
tag = item.text();
}
return {
title: '[' + tag + '] ' + ElementA.text(),
link: ElementA.attr('href').replace('//', 'https://'),
title: '[' + tag + '] ' + aLabelNode.text(),
link: aLabelNode.attr('href').replace('//', 'https://'),
};
})
.get();
@@ -88,21 +78,44 @@ module.exports = async (ctx) => {
const response = await got.get(item.link);
let component = '';
const urlReg = /window.location.replace\('.*'/g;
let pubInfo;
let dateStr;
if (response.body.search(urlReg) < 0) {
const $ = cheerio.load(response.data);
item.author = $('span.GN-lbox3C').text().split(')')[0].split(' 報導')[0].split(' 提供')[0].split(' 同意授權轉載')[0].replace('(', '');
if ($('span.GN-lbox3C').length > 0) {
// official publish 1
pubInfo = $('span.GN-lbox3C').text().split(')');
item.author = pubInfo[0].replace('(', '').replace(' 報導', '');
dateStr = pubInfo[1].trim();
} else {
// official publish 2
pubInfo = $('span.GN-lbox3CA').text().split(')');
item.author = pubInfo[0].replace('(', '').replace(' 報導', '');
dateStr = pubInfo[1].replace('原文出處', '').trim();
}
component = $('div.GN-lbox3B').html();
} else {
// url redirect
const newUrl = response.body.match(urlReg)[0].split('(')[1].replace(/'/g, '');
const _response = await got.get(newUrl);
const _$ = cheerio.load(_response.data);
item.author = _$('span.ST1').text().split('│', 2)[0].split('作者:')[1];
component = _$('div.MSG-list8C').html();
if (!component) {
item.author = _$('a.caption-text.primary').text();
if (_$('div.MSG-list8C').length > 0) {
// personal publish 1
pubInfo = _$('span.ST1').text().split('│');
item.author = pubInfo[0].replace('作者:', '');
dateStr = pubInfo[_$('span.ST1').find('a').length > 0 ? 2 : 1];
component = _$('div.MSG-list8C').html();
} else {
// personal publish 2
pubInfo = _$('div.article-intro').text().replace(/\n/g, '').split('|');
item.author = pubInfo[0];
dateStr = pubInfo[1];
component = _$('div.text-paragraph').html();
}
}
item.pubDate = timezone(parseDate(dateStr, 'YYYY-MM-DD HH:mm:ss'), +8);
component = component.replace(/\b(data-src)\b/g, 'src');
return component;
});