fix(route): xiaohongshu throw captcha error

This commit is contained in:
Tony 2022-07-28 18:48:19 +00:00
parent 4f44368056
commit c43cd4a4a2
2 changed files with 12 additions and 1 deletions

View File

@ -7,7 +7,12 @@ module.exports = async (ctx) => {
const category = ctx.params.category;
const url = `https://www.xiaohongshu.com/user/profile/${userId}`;
const main = await getContent(url, ctx.cache);
let main;
try {
main = await getContent(url, ctx.cache);
} catch (e) {
throw Error('滑块验证');
}
const userDetail = main.userDetail;
const description = `${userDetail.nickname} • 小红书 / RED`;
if (category === 'notes') {

View File

@ -11,6 +11,12 @@ const getContent = (url, cache) =>
page.on('request', (request) => {
request.resourceType() === 'document' || request.resourceType() === 'script' || request.resourceType() === 'xhr' ? request.continue() : request.abort();
});
page.on('response', (response) => {
if (response.url().includes('captcha.fengkongcloud.cn')) {
page.close();
throw Error('滑块验证');
}
});
await page.goto(url);
await page.waitForSelector('.pc-container');
const initialSsrState = await page.evaluate(() => window.__INITIAL_SSR_STATE__);