修改whatshub工单爬虫
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Turnstile 内置求解:等待 widget 自动完成 + token 轮询
|
||||
*/
|
||||
const { detectCloudflare, isTurnstileSolved } = require('./cf-detector');
|
||||
const { detectCloudflare, isTurnstileSolved, urlIndicatesCfChallenge } = require('./cf-detector');
|
||||
|
||||
/**
|
||||
* @typedef {Object} TurnstileResult
|
||||
@@ -22,18 +22,24 @@ async function waitForTurnstile(page, options = {}) {
|
||||
const started = Date.now();
|
||||
|
||||
const initial = await detectCloudflare(page);
|
||||
if (!initial.blocked || initial.hasCfClearance) {
|
||||
return { success: true, stage: 'already_clear', elapsedMs: Date.now() - started };
|
||||
const initialUrlChallenge = urlIndicatesCfChallenge(page.url());
|
||||
|
||||
if ((!initial.blocked && !initialUrlChallenge) || initial.hasCfClearance) {
|
||||
if (initial.hasCfClearance && !initialUrlChallenge) {
|
||||
return { success: true, stage: 'already_clear', elapsedMs: Date.now() - started };
|
||||
}
|
||||
if (!initial.blocked && !initialUrlChallenge) {
|
||||
return { success: true, stage: 'already_clear', elapsedMs: Date.now() - started };
|
||||
}
|
||||
}
|
||||
|
||||
// real browser 已开启 turnstile:true 内置点击;此处轮询等待结果
|
||||
while (Date.now() - started < timeoutMs) {
|
||||
if (await isTurnstileSolved(page)) {
|
||||
if (await isTurnstileSolved(page) && !urlIndicatesCfChallenge(page.url())) {
|
||||
return { success: true, stage: 'built_in', elapsedMs: Date.now() - started };
|
||||
}
|
||||
|
||||
const state = await detectCloudflare(page);
|
||||
if (!state.blocked) {
|
||||
if (!state.blocked && !urlIndicatesCfChallenge(page.url()) && state.hasCfClearance) {
|
||||
return { success: true, stage: 'built_in', elapsedMs: Date.now() - started };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user