fix(route): 北京师范大学 党委学生工作部 - Response code 404 (Not Found) & Invalid URL (#13677)

* 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
This commit is contained in:
People-11 2023-11-03 13:12:07 +11:00 committed by GitHub
parent e37ba00915
commit 705ea99a1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 20 deletions

View File

@ -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;
})
)