diff --git a/lib/v2/bnu/dwxgb.js b/lib/v2/bnu/dwxgb.js index ae224b8c3..e6610138e 100644 --- a/lib/v2/bnu/dwxgb.js +++ b/lib/v2/bnu/dwxgb.js @@ -10,40 +10,35 @@ module.exports = async (ctx) => { let response; try { - response = await got({ - method: 'get', - url: currentUrl, - }); + response = await got(currentUrl); } catch (e) { - currentUrl = `${rootUrl}/${category}/${type}/index.htm`; - response = await got({ - method: 'get', - url: currentUrl, - }); + try { + response = await got(`${rootUrl}/${category}/${type}/index.htm`); + } catch (error) { + return; + } } const $ = cheerio.load(response.data); const list = $('ul.container.list > li') - .map((_, item) => ({ + .map((_, item) => { + const link = $(item).find('a').attr('href'); + const absoluteLink = new URL(link, currentUrl).href; + return { title: $(item).find('a').text().trim(), pubDate: parseDate($(item).find('span').text()), - link: `${rootUrl}/${category}/${type}/${$(item).find('a').attr('href')}`, - })) - .get(); + link: absoluteLink, + }; + }) + .get(); const items = await Promise.all( list.map((item) => ctx.cache.tryGet(item.link, async () => { - const detailResponse = await got({ - method: 'get', - url: item.link, - }); - + const detailResponse = await got(item.link); const content = cheerio.load(detailResponse.data); - item.description = content('div.article.typo').html(); - return item; }) )