feat: add route javlibrary (#3797)

This commit is contained in:
junfengP
2020-02-01 19:46:32 +08:00
committed by GitHub
parent eec4fe626c
commit dae512feb9
14 changed files with 71 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
const cheerio = require('cheerio');
const dateUtil = require('@/utils/date');
const cloudscraper = require('cloudscraper');
const API = 'http://www.javlibrary.com/cn/userposts.php?u=';
module.exports = async (ctx) => {
const uid = ctx.params.uid;
const link = API + uid;
const response = await cloudscraper.get(link);
const $ = cheerio.load(response);
const list = $('div#rightcolumn table.comment');
ctx.state.data = {
title: `Javlibrary - ${uid} 发表的文章`,
link: link,
item:
list &&
list
.map((index, item) => {
item = $(item);
// 文章内容只能抓取到 td.t textarea若含有图片则替换[img]image-link[/img] => <img src="image-link" />
let comments = item.find('td.t textarea').text();
comments = comments.replace(new RegExp('\\[img\\]', 'g'), '<img src="').replace(new RegExp('\\[\\/img\\]', 'g'), '" />');
return {
title: item.find('td > strong').text(),
link: item.find('td > strong > a').attr('href'),
description: `<table>${item.find('table.videoinfo').html()}</table>
<p>${comments}</p>`,
pubDate: dateUtil(item.find('td.date')),
guid: item.find('td > strong > a').attr('href'),
};
})
.get(),
};
};