修改whatshub工单爬虫
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
require('dotenv').config({ path: require('path').join(__dirname, '.env') });
|
||||
|
||||
const express = require('express');
|
||||
const fs = require('fs');
|
||||
const {
|
||||
@@ -45,6 +47,10 @@ const {
|
||||
const { resolveSessionContext, touchSessionIfPresent } = require('./lib/session-context');
|
||||
const { getProfileStats, profileExists } = require('./lib/profile-dir');
|
||||
const { runUiPagination } = require('./lib/ui-pagination-runner');
|
||||
const {
|
||||
awaitPostCfBusinessReady,
|
||||
executeAuthActionsWithDiagnostics,
|
||||
} = require('./lib/post-cf-ready');
|
||||
|
||||
const app = express();
|
||||
app.use(express.json({ limit: '50mb' }));
|
||||
@@ -75,7 +81,11 @@ function sendTaskError(res, error, extra = {}) {
|
||||
}
|
||||
const errType = classifyPuppeteerError(error);
|
||||
console.error(`[${errType}]`, error.message);
|
||||
return res.status(500).json({ success: false, error: error.message, ...extra });
|
||||
const payload = { success: false, error: error.message, ...extra };
|
||||
if (error.pageDiagnostics) {
|
||||
payload.page = error.pageDiagnostics;
|
||||
}
|
||||
return res.status(500).json(payload);
|
||||
}
|
||||
|
||||
async function navigateToPage(page, url) {
|
||||
@@ -524,7 +534,11 @@ app.post('/api/auth-and-intercept', async (req, res) => {
|
||||
await seedShareTokenCookie(page, finalPageUrl);
|
||||
}
|
||||
|
||||
await executeAuthActions(page, authActions);
|
||||
if (antiBot.enabled) {
|
||||
await awaitPostCfBusinessReady(page, antiBot, waitForUrlSettled);
|
||||
}
|
||||
|
||||
await executeAuthActionsWithDiagnostics(page, authActions, executeAuthActions);
|
||||
await interceptor.waitForApis(interceptTimeout);
|
||||
|
||||
const rawCookies = await page.cookies();
|
||||
@@ -758,6 +772,10 @@ app.post('/api/ui-pagination', async (req, res) => {
|
||||
touchSessionIfPresent(antiBot.sessionKey);
|
||||
}
|
||||
|
||||
if (antiBot.enabled) {
|
||||
await awaitPostCfBusinessReady(page, antiBot, waitForUrlSettled);
|
||||
}
|
||||
|
||||
const paginationResult = await runUiPagination(page, {
|
||||
apiUrl,
|
||||
nextBtnSelector,
|
||||
@@ -874,7 +892,11 @@ app.post('/api/auth-intercept-and-paginate', async (req, res) => {
|
||||
touchSessionIfPresent(antiBot.sessionKey);
|
||||
}
|
||||
|
||||
await executeAuthActions(page, authActions);
|
||||
if (antiBot.enabled) {
|
||||
await awaitPostCfBusinessReady(page, antiBot, waitForUrlSettled);
|
||||
}
|
||||
|
||||
await executeAuthActionsWithDiagnostics(page, authActions, executeAuthActions);
|
||||
await interceptor.waitForApis(interceptTimeout);
|
||||
|
||||
const rawCookies = await page.cookies();
|
||||
|
||||
Reference in New Issue
Block a user