On branch master

Your branch is up to date with 'origin/master'.

 Changes to be committed:
	modified:   lib/routes/gamer/gnn_index.js
	modified:   lib/routes/yomiuri/news.js
This commit is contained in:
arracc
2020-10-01 23:44:46 +08:00
parent 55d89717e5
commit 9679b09eea
2 changed files with 84 additions and 103 deletions

View File

@@ -46,96 +46,78 @@ module.exports = async (ctx) => {
});
const data = response.data;
const $ = cheerio.load(data);
const list = $('div.BH-lbox.GN-lbox2').children().not('.GN-lbox2A').not('.GN-lbox2G');
const list = $('div.BH-lbox.GN-lbox2').children().not('.GN-lbox2A').not('.GN-lbox2G')
.map((item) => {
item = $(item);
let element_a;
let tag;
if (item.attr('class') === 'GN-lbox2F') {
element_a = item.find('a').eq(0);
tag = item.children('img').eq(0).attr('class');
} else {
element_a = item.find('a').eq(1);
tag = item.children('h1').children('img').eq(0).attr('class');
}
if (tag === 'IMG-Gmuti') {
tag = 'General';
} else if (tag === 'IMG-GA19') {
tag = 'PC';
} else if (tag === 'IMG-GB3') {
tag = 'NS';
} else if (tag === 'IMG-GB4') {
tag = 'PS5';
} else if (tag === 'IMG-GB1') {
tag = 'PS4';
} else if (tag === 'IMG-GA14') {
tag = 'ARC';
} else if (tag === 'IMG-GAC') {
tag = 'AC';
} else if (tag === 'IMG-GA13') {
tag = 'ETC';
} else if (tag === 'IMG-GA1') {
tag = 'OLG';
} else if (tag === 'IMG-Gmobi') {
tag = 'MOBI';
} else if (tag === 'IMG-GA20') {
tag = 'WEB';
} else if (tag === 'IMG-GA25') {
tag = 'Google';
} else if (tag === 'IMG-GA24') {
tag = 'Apple';
} else if (tag === 'IMG28') {
tag = 'Facebook';
} else if (tag === 'IMG-GA17' || tag === 'IMG-Gother') {
tag = 'Other';
} else {
tag = 'Unclassified';
}
const out = await Promise.all(
list &&
list
.map(async (index, item) => {
item = $(item);
let element_a;
let tag;
if (item.attr('class') === 'GN-lbox2F') {
element_a = item.find('a').eq(0);
tag = item.children('img').eq(0).attr('class');
} else {
element_a = item.find('a').eq(1);
tag = item.children('h1').children('img').eq(0).attr('class');
}
if (tag === 'IMG-Gmuti') {
tag = 'General';
} else if (tag === 'IMG-GA19') {
tag = 'PC';
} else if (tag === 'IMG-GB3') {
tag = 'NS';
} else if (tag === 'IMG-GB4') {
tag = 'PS5';
} else if (tag === 'IMG-GB1') {
tag = 'PS4';
} else if (tag === 'IMG-GA14') {
tag = 'ARC';
} else if (tag === 'IMG-GAC') {
tag = 'AC';
} else if (tag === 'IMG-GA13') {
tag = 'ETC';
} else if (tag === 'IMG-GA1') {
tag = 'OLG';
} else if (tag === 'IMG-Gmobi') {
tag = 'MOBI';
} else if (tag === 'IMG-GA20') {
tag = 'WEB';
} else if (tag === 'IMG-GA25') {
tag = 'Google';
} else if (tag === 'IMG-GA24') {
tag = 'Apple';
} else if (tag === 'IMG28') {
tag = 'Facebook';
} else if (tag === 'IMG-GA17' || tag === 'IMG-Gother') {
tag = 'Other';
} else {
tag = 'Unclassified';
}
return {
title: '[' + tag + '] ' + element_a.text(),
link: element_a.attr('href').replace('//', 'https://'),
}
})
.get();
const title = '[' + tag + '] ' + element_a.text();
const link = element_a.attr('href').replace('//', 'https://');
// 图片延迟加载无法获取源地址;
const content = await got({
method: 'get',
url: link,
});
const c = cheerio.load(content.data);
const description = c('div.GN-lbox3B').children('div').html();
// // 使用 RSSHub 提供的 puppeteer 工具类,初始化 Chrome 进程
// const browser = await require('@/utils/puppeteer')();
// // 创建一个新的浏览器页面
// const page = await browser.newPage();
// // 访问指定的链接
// await page.goto(link);
// // 渲染目标网页
// // const html = await page.evaluate(() => document.querySelector('div.gnn-detail-cont').innerHTML);
// const html = await page.$eval('div.gnn-detail-cont', (e) => e.innerHTML);
// // 关闭浏览器进程
// browser.close();
// const c = cheerio.load(html);
// const description = c('div.GN-lbox3B').children('div').html();
return {
title,
description,
link,
};
})
.get()
const items = await Promise.all(
list.map(async (item) => {
// 图片延迟加载无法获取源地址;
const content = await got({
method: 'get',
url: item.link,
});
const c = cheerio.load(content.data);
item.description = c('div.GN-lbox3B').children('div').html();
return {
item,
}
})
);
ctx.state.data = {
title: '巴哈姆特-GNN新闻-' + category_name,
link: url,
item: out,
item: items,
};
};

View File

@@ -22,30 +22,29 @@ module.exports = async (ctx) => {
list = $('div.p-category-organization,.p-category-time-series').find('li').not('.p-member-only').not('.p-ad-list-item');
}
const out = await Promise.all(
list &&
list
.map(async (index, item) => {
item = $(item);
const link = item.find('a').attr('href');
const content = await got({
method: 'get',
url: link,
});
const c = cheerio.load(content.data);
const description = c('div.p-main-contents').html();
return {
title: item.find('a').text(),
description,
link: item.find('a').attr('href'),
};
})
.get()
const items = await Promise.all(
list
.map(async (index, item) => {
item = $(item);
const link = item.find('a').attr('href');
const content = await got({
method: 'get',
url: link,
});
const c = cheerio.load(content.data);
const description = c('div.p-main-contents').html();
return {
title: item.find('a').text(),
description,
link,
};
})
.get()
);
ctx.state.data = {
title: '読売新聞-' + category_name,
link: url,
item: out,
item: items,
};
};