验证码解算器 使用抓取浏览器浏览页面时,默认情况下,我们的集成验证码解算器会自动解算所有验证码 。您可以使用以下自定义 CDP 函数在代码中监控此自动解算过程。 
验证码解算后,如有表单需要提交,则默认情况下会提交。 
验证码解算器 - 自动解算 
使用此指令返回验证码已解算、失败或未检测到之后的状态。
使用此指令返回验证码已解算、失败或未检测到之后的状态。 Captcha.Solve
SolveResult
SolveStatus
Captcha . Solve ({     detectTimeout? :  number  // Detect timeout in millisecond for solver to detect captcha       options ?:  CaptchaOptions []  // Configuration options for captcha solving   }) :  SolveResult 
示例 NodeJS - Puppeteer
Python - Playwright
const  page  =  await  browser . newPage (); const  client  =  await  page . target (). createCDPSession (); await  page . goto ( '[https://site-with-captcha.com](https://site-with-captcha.com/)' );   // Note 1: If no captcha was found it will return not_detected status after detectTimeout    // Note 2: Once a CAPTCHA is solved, if there is a form to submit, it will be submitted by default    const  client  =  await  page . target (). createCDPSession ();   const  { status }  =  await  client . send ( 'Captcha.Solve' , { detectTimeout:  30 * 1000 });    console . log ( `Captcha solve status:  ${ status } ` ) 
如果验证码解算失败,请重新尝试。 如果问题仍然存在,请提交支持请求 ,详细说明您遇到的具体问题。 
使用以下指令查明验证码解算流程中更具体的阶段: Captcha.detected抓取浏览器遇到验证码并开始解算 Captcha.SolveFinished抓取浏览器成功解算验证码 Captcha.SolveFailed抓取浏览器未能解算验证码 Captcha.waitForSolve抓取浏览器等待验证码解算器完成 
示例 以下代码设置 CDP 会话、监听 CAPTCHA 事件并处理超时: NodeJS - Puppeteer
Python - Playwright
// Node.js - Puppeteer - waiting for CAPTCHA solving events   const  client  =  await  page . target (). createCDPSession ();    await  new  Promise (( resolve ,  reject ) => {      client . on ( 'Captcha.SolveFinished' ,  resolve );      client . on ( 'Captcha.SolveFailed' , () => reject ( new  Error ( 'Captcha failed' )));      setTimeout ( reject ,  5  *  60  *  1000 ,  new  Error ( 'Captcha solve timeout' ));   }); 
验证码解算器 - 手动控制 如果您想手动配置或完全禁用我们的默认验证码解算器,请改为手动调用解算器或自己解算,请参阅以下 CDP 指令和功能。 
此指令用于控制验证码的自动解算。 您可以禁用自动解算或为不同的验证码类型配置算法,然后手动触发此操作: Captcha.setAutoSolve
CaptchaOptions
Captcha . setAutoSolve ({     autoSolve:  boolean  // Whether to automatically solve captcha after navigate     options ?:  CaptchaOptions []  // Configuration options for captcha auto-solving   }) :  void 
在会话中完全禁用自动解算器的 CDP 指令示例: NodeJS - Puppeteer
Python - Playwright
- Selenium
// Node.js Puppeteer - Disable Captcha auto-solver completely   const  page  =  await  browser . newPage ();   const  client  =  await  page . target (). createCDPSession ();   await  client . send ( 'Captcha.setAutoSolve' , {  autoSolve:  false  }) 
NodeJS - Puppeteer
Python - Playwright
// Node.js Puppeteer - Disable Captcha auto-solver for ReCaptcha only   const  page  =  await  browser . newPage ();   const  client  =  await  page . target (). createCDPSession ();   await  client . send ( 'Captcha.setAutoSolve' , {       autoSolve:  true ,       options:  [{           type:  'usercaptcha' ,           disabled:  true ,       }],   }); 
NodeJS - Puppeteer
Python - Playwright
Python - Selenium
// Node.js Puppeteer - manually solving CAPTCHA after navigation   const  page  =  await  browser . newPage ();   const  client  =  await  page . target (). createCDPSession ();   await  client . send ( 'Captcha.setAutoSolve' , {  autoSolve:  false  });   await  page . goto ( 'https://site-with-captcha.com' , {  timeout:  2 * 60 * 1000  });   const  { status }  =  await  client . send ( 'Captcha.Solve' , {  detectTimeout:  30 * 1000  });   console . log ( 'Captcha solve status:' ,  status ); 
对于以下三种验证码类型,我们支持以下附加选项,以控制和配置我们的自动解算算法。  CF Challenge
 HCaptcha
 usercaptcha (reCAPTCHA)
timeout :  40000    selector :  '#challenge-body-text, .challenge-form'    check_timeout :  300    error_selector :  '#challenge-error-title'    success_selector :  '#challenge-success[style*=inline]'    check_success_timeout :  300    btn_selector :  '#challenge-stage input[type=button]'    cloudflare_checkbox_frame_selector :  '#turnstile-wrapper iframe'    checkbox_area_selector :  '.ctp-checkbox-label .mark'    wait_timeout_after_solve :  500    wait_networkidle : { timeout :  500 } 仿真函数 
Emulation.getSupportedDevices
使用此指令获取所有可仿真的设备列表。 此方法返回可与 setDevice 指令一起使用的设备选项阵列。 Emulation . getSupportedDevices (). then ( devices  =>  {  console . log ( devices );}); 
收到上面的支持设备列表后,您可以使用 Emulation.setDevice 指令模拟特定设备。此指令更改屏幕宽度、高度、userAgent 和 devicePixelRatio 以匹配指定的设备。 Emulation . setDevice ({ device:  '[device_name]' }); 
横向模式 如果您想将方向更改为横向(适用于支持横向的设备),可在device_name 之后添加字符串landscape。 Emulation . setDevice ({ device:  'iPhone X landscape' });