From 54aea54dd6bb01d7386cc18db0bb7ad9e2b3b010 Mon Sep 17 00:00:00 2001 From: Felix Hsu Date: Wed, 25 Jan 2023 18:38:21 +0800 Subject: [PATCH] fix(route): bloomberg videopage parse error (#11688) --- lib/v2/bloomberg/utils.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/v2/bloomberg/utils.js b/lib/v2/bloomberg/utils.js index 7526910324..40f2874bb3 100644 --- a/lib/v2/bloomberg/utils.js +++ b/lib/v2/bloomberg/utils.js @@ -23,7 +23,7 @@ const apiEndpoints = { }, videos: { url: 'https://www.bloomberg.com/news/videos/', - sel: '.footer-container + script', + sel: 'script', }, newsletters: { url: 'https://www.bloomberg.com/news/newsletters/', @@ -153,7 +153,9 @@ const parseAudioPage = async (res, api, item) => { }; const parseVideoPage = async (res, api, item) => { - const json = cheerio.load(res.data)(api.sel).text().trim().replace('window.__PRELOADED_STATE__ = ', '').slice(0, -1); + const $ = cheerio.load(res.data); + const script = $(api.sel).filter((i, el) => $(el).text().includes('__PRELOADED_STATE__')); + const json = script.text().trim().replace('window.__PRELOADED_STATE__ = ', '').slice(0, -1); const article_json = JSON.parse(json); const video_story = article_json.video?.videoStory ?? article_json.quicktakeVideo?.videoStory; if (video_story) {