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,14 +46,9 @@ 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 out = await Promise.all(
list &&
list
.map(async (index, item) => {
const list = $('div.BH-lbox.GN-lbox2').children().not('.GN-lbox2A').not('.GN-lbox2G')
.map((item) => {
item = $(item);
let element_a;
let tag;
@@ -98,44 +93,31 @@ module.exports = async (ctx) => {
tag = 'Unclassified';
}
const title = '[' + tag + '] ' + element_a.text();
const link = element_a.attr('href').replace('//', 'https://');
return {
title: '[' + tag + '] ' + element_a.text(),
link: element_a.attr('href').replace('//', 'https://'),
}
})
.get();
const items = await Promise.all(
list.map(async (item) => {
// 图片延迟加载无法获取源地址;
const content = await got({
method: 'get',
url: link,
url: item.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();
item.description = c('div.GN-lbox3B').children('div').html();
return {
title,
description,
link,
};
item,
}
})
.get()
);
ctx.state.data = {
title: '巴哈姆特-GNN新闻-' + category_name,
link: url,
item: out,
item: items,
};
};

View File

@@ -22,8 +22,7 @@ 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 &&
const items = await Promise.all(
list
.map(async (index, item) => {
item = $(item);
@@ -37,7 +36,7 @@ module.exports = async (ctx) => {
return {
title: item.find('a').text(),
description,
link: item.find('a').attr('href'),
link,
};
})
.get()
@@ -46,6 +45,6 @@ module.exports = async (ctx) => {
ctx.state.data = {
title: '読売新聞-' + category_name,
link: url,
item: out,
item: items,
};
};