fix(route): ielts window.$ is not a function (#9255)

This commit is contained in:
Tony 2022-03-06 17:31:52 +03:00 committed by GitHub
parent fbcba24a9f
commit 0b4ea2ee67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 13 deletions

View File

@ -15,21 +15,21 @@ module.exports = async (ctx) => {
await page.goto(targetUrl, {
waitUntil: 'networkidle0',
});
const list = await page.evaluate(() =>
window
.$('#newsListUl li')
.get()
.map((elem) => {
const $elem = window.$(elem);
return {
title: $elem.find('a').text(),
link: $elem.find('a').attr('href'),
pubDate: $elem.find('span').eq(-1).text().replace(/[[\]]/g, '').trim(),
};
})
);
const html = await page.evaluate(() => document.body.innerHTML);
browser.close();
const $ = cheerio.load(html);
const list = $('#newsListUl li')
.get()
.map((elem) => {
const $elem = $(elem);
return {
title: $elem.find('a').text(),
link: $elem.find('a').attr('href'),
pubDate: $elem.find('span').eq(-1).text().replace(/[[\]]/g, '').trim(),
};
});
list.sort((a, b) => parseDate(b.pubDate) - parseDate(a.pubDate));
list.forEach((item) => {
item.pubDate = timezone(parseDate(item.pubDate), +8);