RSSHub/lib/v2/hacking8/index.js

46 lines
1.3 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const category = ctx.params.category ?? 'index';
const rootUrl = 'https://i.hacking8.com';
const currentUrl = `${rootUrl}/index/${category}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
const items = $('div.media')
.toArray()
.map((item) => {
item = $(item);
const a = item.find('div.link a');
return {
title: a.text(),
link: new URL(a.attr('href'), rootUrl).href,
description: item.find('div.media-body pre').text(),
pubDate: timezone(parseDate(item.parent().parent().find('td').first().text(), 'YYYY年M月D日 HH:mm'), +8),
category: item
.parent()
.parent()
.find('span.label')
.toArray()
.map((l) => $(l).text()),
};
});
ctx.state.data = {
title: `Hacking8 安全信息流 - ${$('div.btn-group a.btn-primary').text()}`,
link: currentUrl,
item: items,
};
};