Skip to content

Commit

Permalink
fix(route): xiaohongshu (#13909)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored Nov 29, 2023
1 parent ee901f8 commit 173d0de
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions lib/v2/xiaohongshu/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 173d0de

Please sign in to comment.