fix: latest comments from lowendtalk discussions (#6437)

This commit is contained in:
Ethan Shen
2020-12-14 11:50:48 +00:00
committed by GitHub
parent 14fc4af1ef
commit 0aeee4fa99
+10 -3
View File
@@ -4,12 +4,19 @@ const cheerio = require('cheerio');
module.exports = async (ctx) => {
const rootUrl = 'https://www.lowendtalk.com';
const currentUrl = `${rootUrl}/discussion/${ctx.params.id}`;
const response = await got({
let response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
let $ = cheerio.load(response.data);
response = await got({
method: 'get',
url: $('.LastPage').attr('href'),
});
$ = cheerio.load(response.data);
const items = $('.userContent')
.map((_, item) => {
@@ -29,7 +36,7 @@ module.exports = async (ctx) => {
.get();
ctx.state.data = {
title: $('title').text(),
title: $('h1').eq(0).text(),
link: currentUrl,
item: items,
};