From 32dd0a7590a06e2b10ba5acfe9e89c6048b91d23 Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 30 Jul 2026 08:19:59 +0800 Subject: [PATCH] fix(route/zaobao): update selector (#22876) * fix(route/zaobao): update selector * fix(route/zaobao): refine parseList to improve JSON handling and data extraction --- lib/routes/zaobao/util.tsx | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/routes/zaobao/util.tsx b/lib/routes/zaobao/util.tsx index b7656da86..47e6f30f7 100644 --- a/lib/routes/zaobao/util.tsx +++ b/lib/routes/zaobao/util.tsx @@ -58,27 +58,24 @@ export const parseList = async ( const response = await ofetch.raw(new URL($item.attr('href') as string, origin).href); let $1 = load(response._data); - let title, pubDate, category, images; - const jsonText = $1('script[type="application/ld+json"]') + let category, images; + const jsonText = $1('script[type="application/ld+json"]:contains("NewsArticle")') .text() .replaceAll(/\p{Cc}/gu, ''); const ldJson = JSON.parse(jsonText); + const title = ldJson.headline; + const pubDate = parseDate(ldJson.datePublished); + const isSingapore = response.url.startsWith('https://www.zaobao.com.sg/'); if (isSingapore) { - const ldJson = JSON.parse($1('#seo-article-page').text()); - const article = ldJson['@graph'].find((item) => item['@type'] === 'NewsArticle'); - title = article.headline; - pubDate = parseDate(article.datePublished); category = $1('meta[name="keywords"]') .attr('content') ?.split(',') .map((s) => s.trim()); $1 = load($1('.articleBody').html(), null, false); - images = [{ url: article.image.url }]; + images = [{ url: ldJson.image[0].url }]; } else { - title = ldJson.headline; - pubDate = parseDate(ldJson.datePublished); category = ldJson.keywords?.split(','); }