fix(route/parliament.uk): page link and items selector (#17129)

* chore(route): add nytimes popular routes

* fix(route/parliament.uk): fix return link

* fix(route/parliament.uk): fix items selector

---------
This commit is contained in:
xxx.Yan
2024-10-15 02:36:17 +08:00
committed by GitHub
parent e953515cd2
commit bf66164260
2 changed files with 8 additions and 8 deletions
+4 -4
View File
@@ -23,8 +23,8 @@ export const route: Route = {
async function handler(ctx) {
const { topic } = ctx.req.param();
const baseUrl = 'https://commonslibrary.parliament.uk/type';
const url = `${baseUrl}/${topic}/`;
const baseUrl = 'https://commonslibrary.parliament.uk';
const url = `${baseUrl}/type/${topic}/`;
const browser = await puppeteer();
const page = await browser.newPage();
await page.setRequestInterception(true);
@@ -38,7 +38,7 @@ async function handler(ctx) {
const html = await page.evaluate(() => document.documentElement.innerHTML);
await page.close();
const $ = load(html);
const items = $('article.card--horizontal')
const items = $('div.l-box.l-box--no-border.card__text')
.map((_, article) => ({
title: $(article).find('.card__text a').text().trim(),
link: $(article).find('.card__text a').attr('href'),
@@ -49,7 +49,7 @@ async function handler(ctx) {
browser.close();
return {
title: `parliament - lordslibrary - ${topic}`,
link: baseUrl,
link: url,
item: items,
};
}
+4 -4
View File
@@ -23,8 +23,8 @@ export const route: Route = {
async function handler(ctx) {
const { topic } = ctx.req.param();
const baseUrl = 'https://lordslibrary.parliament.uk/type';
const url = `${baseUrl}/${topic}/`;
const baseUrl = 'https://lordslibrary.parliament.uk';
const url = `${baseUrl}/type/${topic}/`;
const browser = await puppeteer();
const page = await browser.newPage();
await page.setRequestInterception(true);
@@ -38,7 +38,7 @@ async function handler(ctx) {
const html = await page.evaluate(() => document.documentElement.innerHTML);
await page.close();
const $ = load(html);
const items = $('article.card--horizontal')
const items = $('div.l-box.l-box--no-border.card__text')
.map((_, article) => ({
title: $(article).find('.card__text a').text().trim(),
link: $(article).find('.card__text a').attr('href'),
@@ -49,7 +49,7 @@ async function handler(ctx) {
browser.close();
return {
title: `parliament - lordslibrary - ${topic}`,
link: baseUrl,
link: url,
item: items,
};
}