fix(route): bloomberg videopage parse error (#11688)

This commit is contained in:
Felix Hsu
2023-01-25 02:38:21 -08:00
committed by GitHub
parent 97900106e0
commit 54aea54dd6
+4 -2
View File
@@ -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) {