diff --git a/lib/v2/xiaohongshu/util.js b/lib/v2/xiaohongshu/util.js index 2ac4bdf76..ecffddd15 100644 --- a/lib/v2/xiaohongshu/util.js +++ b/lib/v2/xiaohongshu/util.js @@ -14,20 +14,30 @@ const getUser = (url, cache) => page.on('request', (request) => { request.resourceType() === 'document' || request.resourceType() === 'script' || request.resourceType() === 'xhr' || request.resourceType() === 'other' ? request.continue() : request.abort(); }); - logger.debug(`Requesting ${url}`); + logger.http(`Requesting ${url}`); await page.goto(url, { waitUntil: 'domcontentloaded', }); await page.waitForSelector('div.reds-tab-item:nth-child(2)'); - await page.click('div.reds-tab-item:nth-child(2)'); - const response = await page.waitForResponse((res) => { - const req = res.request(); - return req.url().includes('/api/sns/web/v2/note/collect/page') && req.method() === 'GET' && req.resourceType() === 'xhr'; - }); - collect = await response.json(); const initialState = await page.evaluate(() => window.__INITIAL_STATE__); + if (!(await page.$('.lock-icon'))) { + await page.click('div.reds-tab-item:nth-child(2)'); + try { + const response = await page.waitForResponse( + (res) => { + const req = res.request(); + return req.url().includes('/api/sns/web/v2/note/collect/page') && req.method() === 'GET' && req.resourceType() === 'xhr'; + }, + { timeout: 5000 } + ); + collect = await response.json(); + } catch (e) { + // + } + } + let { userPageData, notes } = initialState.user; userPageData = userPageData._rawValue || userPageData; notes = notes._rawValue || notes;