diff --git a/lib/v2/xiaohongshu/util.js b/lib/v2/xiaohongshu/util.js index 8ebf8dd6d6..c4d9ef7c1a 100644 --- a/lib/v2/xiaohongshu/util.js +++ b/lib/v2/xiaohongshu/util.js @@ -114,52 +114,49 @@ const getNotes = (url, cache) => const notesPromise = userPosted.data.notes.map((n) => { const noteUrl = url + '/' + n.note_id; - return cache.tryGet( - noteUrl, - async () => { - const notePage = await browser.newPage(); - await setPageFilter(notePage); + return cache.tryGet(noteUrl, async () => { + const notePage = await browser.newPage(); + await setPageFilter(notePage); - logger.debug(`Requesting ${noteUrl}`); - await notePage.goto(noteUrl); + logger.debug(`Requesting ${noteUrl}`); + await notePage.goto(noteUrl); - let feed = {}; - try { - feed = await notePage.evaluate(() => window.__INITIAL_STATE__); + let feed = {}; + try { + feed = await notePage.evaluate(() => window.__INITIAL_STATE__); - // Sometimes the page is not server-side rendered - if (typeof feed?.note?.note === 'undefined' || JSON.stringify(feed?.note?.note) === '{}') { - const res = await notePage.waitForResponse((res) => { - const req = res.request(); - return req.url().includes('/api/sns/web/v1/feed') && req.method() === 'POST'; - }); + // Sometimes the page is not server-side rendered + if (typeof feed?.note?.note === 'undefined' || JSON.stringify(feed?.note?.note) === '{}') { + const res = await notePage.waitForResponse((res) => { + const req = res.request(); + return req.url().includes('/api/sns/web/v1/feed') && req.method() === 'POST'; + }); - const json = await res.json(); - const note_card = json.data.items[0].note_card; - feed.note.note = { - title: note_card.title, - noteId: note_card.id, - desc: note_card.desc, - tagList: note_card.tag_list, - imageList: note_card.image_list, - user: note_card.user, - time: note_card.time, - lastUpdateTime: note_card.last_update_time, - }; - } - } catch (e) { - throw Error(`Could not get note ${n.note_id}\n${e}`); - } - - await notePage.close(); - - if (typeof feed?.note?.note !== 'undefined' && JSON.stringify(feed?.note?.note) !== '{}') { - return feed.note.note; - } else { - throw Error(`Could not get note ${n.note_id}`); + const json = await res.json(); + const note_card = json.data.items[0].note_card; + feed.note.note = { + title: note_card.title, + noteId: note_card.id, + desc: note_card.desc, + tagList: note_card.tag_list, + imageList: note_card.image_list, + user: note_card.user, + time: note_card.time, + lastUpdateTime: note_card.last_update_time, + }; } + } catch (e) { + throw Error(`Could not get note ${n.note_id}\n${e}`); } - ); + + await notePage.close(); + + if (typeof feed?.note?.note !== 'undefined' && JSON.stringify(feed?.note?.note) !== '{}') { + return feed.note.note; + } else { + throw Error(`Could not get note ${n.note_id}`); + } + }); }); user = otherInfo.data.basic_info;