fix(route): xiaohongshu puppeteer parsing

This commit is contained in:
Tony 2022-06-28 17:23:35 +00:00 committed by GitHub
parent 0f72967759
commit 0f275d6532
1 changed files with 2 additions and 6 deletions

View File

@ -13,12 +13,8 @@ const getContent = (url, cache) =>
});
await page.goto(url);
await page.waitForSelector('.pc-container');
let content = await page.content();
content = content.replace('"RedAppLayout":undefined,', ''); // fix json parse
const regex = /_SSR_STATE__\S*=([\s\S]+)<\/script>/gm;
const match = regex.exec(content);
return JSON.parse(match[1]).Main;
const initialSsrState = await page.evaluate(() => window.__INITIAL_SSR_STATE__);
return initialSsrState.Main;
} finally {
browser.close();
}