Skip to content

Commit

Permalink
fix(route): 北京师范大学 党委学生工作部 - Response code 404 (Not Found) & Invalid …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
People-11 authored Nov 3, 2023
1 parent e37ba00 commit 705ea99
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions lib/v2/bnu/dwxgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
)
Expand Down

0 comments on commit 705ea99

Please sign in to comment.