From 705ea99a1ed009f1145bb72fbf2f5547bce1405e Mon Sep 17 00:00:00 2001 From: People-11 <41558215+People-11@users.noreply.github.com> Date: Fri, 3 Nov 2023 13:12:07 +1100 Subject: [PATCH] =?UTF-8?q?fix(route):=20=E5=8C=97=E4=BA=AC=E5=B8=88?= =?UTF-8?q?=E8=8C=83=E5=A4=A7=E5=AD=A6=20=E5=85=9A=E5=A7=94=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E5=B7=A5=E4=BD=9C=E9=83=A8=20-=20Response=20code=2040?= =?UTF-8?q?4=20(Not=20Found)=20&=20Invalid=20URL=20(#13677)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update dwxgb.js Fix #13675 * Update dwxgb.js Use 'url.URL' constructor instead. * Update dwxgb.js I forgot * Update dwxgb.js Try to unify code style * Update dwxgb.js Alright.... Original I just fix problems --- lib/v2/bnu/dwxgb.js | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) 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; }) )