博客
如何使用Puppeteer和Capsolver扩展如何使用Puppeteer和Capsolver扩展程序谷歌插件解决hCaptcha程序谷歌插件解决reCaptcha

如何使用 Puppeteer 和 Capsolver 扩展程序谷歌插件通过hCaptcha

Logo of Capsolver

CapSolver Blogger

How to use capsolver

24-Jul-2023

如何使用 Puppeteer 和 Capsolver 扩展程序解决 hCaptcha

1. 安装 Puppeteer 组件

在本文中,我们将介绍如何使用 capsolver 扩展程序设置 puppeteer js 以解决 reCaptcha v2。但是,您可以将此应用于所有 captcha。

npm i puppeteer puppeteer-extra puppeteer-extra-plugin-stealth

2. 设置扩展程序

下载 ↗扩展程序的压缩文件并将其解压到项目根目录下的./CapSolver.Browser.Extension文件夹中。

该扩展程序有许多设置,包括自动解决指定类型的 captcha、代理支持和其他设置。这些设置在文件./assets/config.json中可用。

这些设置包括:

{
    "apiKey": "YourApiKey",
  "useCapsolver": true, Ex: true / false

  "useProxy": false, Ex: true / false
  "proxyType": "http", Ex: http / socks5 / socks4
  "hostOrIp": "", Ex: @google.com or 154.3.2.3
  "port": "", Ex: 8983
  "proxyLogin": "", Optional. Ex: dkkwje
  "proxyPassword": "", Optional. Ex: dkwjek

  "enabledForBlacklistControl": false, Ex: true / false
  "blackUrlList": [], 

  "enabledForRecaptcha": true, Ex: true / false
  "enabledForRecaptchaV3": true, Ex: true / false
  "enabledForHCaptcha": true, Ex: true / false
  "enabledForFunCaptcha": true, Ex: true / false

  "reCaptchaMode": "click", Ex: click / token
  "hCaptchaMode": "token",  Ex: click / token

  "reCaptchaDelayTime": 0,
  "hCaptchaDelayTime": 0,

  "reCaptchaRepeatTimes": 10,
  "reCaptcha3RepeatTimes": 10,
  "hCaptchaRepeatTimes": 10,
  "funCaptchaRepeatTimes": 10
}

在扩展程序设置文件./assets/config.json中输入您的 API 密钥。您的密钥必须写入 apiKey 字段的值。您可以在页面上查看和复制您的 API 密钥。

例如:apiKey: "CAP-4FDBD3SDFSD-23S-2-3"

在本例中,我们将使用 hCaptchaMode token,但我们也可以使用 click。对于 hCaptcha,建议使用 token 模式。

3. 使用 Puppeteer 和 Capsolver 扩展程序设置解决 hCaptcha

const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
const { executablePath } = require('puppeteer'); 

(async () => {
  const pathToExtension = require('path').join(__dirname, 'CapSolver.Browser.Extension');
  puppeteer.use(StealthPlugin())
  const browser = await puppeteer.launch({
    headless: false,
    args: [
      `--disable-extensions-except=${pathToExtension}`,
      `--load-extension=${pathToExtension}`,
    ],
    executablePath: executablePath()
  });
  
  const [page] = await browser.pages()
  // 打开页面
await page.goto('https://site.example') 

// 等待 CSS 选择器 "#checkbox" 的元素可用
await page.waitForSelector('#checkbox')
// 单击具有指定选择器的元素
await page.click('#checkbox')
})();

接下来,打开页面 https://site.example,并将 captcha 发送到 capsolver。

使用 page.goto() 转到页面 https://site.example。接下来,您需要手动或自动发送 captcha 进行解决。

在我们的示例中,我们将手动发送 captcha,为此我们等待具有 CSS 选择器 #recaptcha-anchor-label 的扩展程序按钮可用,然后单击该按钮。单击按钮后,captcha 将进入服务进行解决。

这是全部内容!您使用 Capsolver 扩展程序和 Puppeteer 成功解决了 hCaptcha。如果您需要解决其他 captcha,只需为其他 captcha 复制本教程即可。

Capsolver团队 💜
加入我们
中文代理QQ群:497493756

更多