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

Emma Foster
Machine Learning Engineer
24-Jul-2023
1. 安装 Puppeteer 组件
在这篇博客中,我们将解释如何使用 Capsolver 扩展程序设置 Puppeteer JS,以解决 reCaptcha v2。但是,您也可以将此方法应用于所有其他类型的验证码。
npm i puppeteer puppeteer-extra puppeteer-extra-plugin-stealth
2. 设置扩展程序
下载扩展程序压缩包 ↗,並將其解壓到項目根目錄下的 ./CapSolver.Browser.Extension
文件夾中。
該擴展程序有許多設置,包括自動解決指定類型的驗證碼、支持代理和其他設置。這些設置在 ./assets/config.json
文件中可用。
這些設置包括:
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
"enabledForcaptcha": true, Ex: true / false
"enabledForcaptcha": true, Ex: true / false
"reCaptchaMode": "token", Ex: click / token
"captchaMode": "click", Ex: click / token
"reCaptchaDelayTime": 0,
"captchaDelayTime": 0,
"reCaptchaRepeatTimes": 10,
"reCaptcha3RepeatTimes": 10,
"captchaRepeatTimes": 10,
"captchaRepeatTimes": 10
}
您需要在擴展程序設置文件 ./assets/config.json
中输入您的 API 密钥。您的密钥必须写入 apiKey
字段的值中。您可以在该页面上查看并复制 API 密钥。
例如:apiKey: "CAP-4FDBD3SDFSD-23S-2-3"
在本例中,我们将使用 reCaptchaMode token,但我们也可以使用 click,对于 reCaptcha,建议使用 token 模式。
3. 为使用 Capsolver 扩展程序解决 reCaptcha 设置 Puppeteer
js
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()
})();
接下來,打開頁面 https://www.google.com/recaptcha/api2/demo ↗,并将验证码发送到 Capsolver。
使用 page.goto()
去到頁面 https://www.google.com/recaptcha/api2/demo ↗。接下來,您需要手動或自動發送驗證碼進行解決。
在我们的示例中,我们将手动发送验证码,为此,我们等待具有 CSS 选择器 #recaptcha-anchor-label
的擴展程序按鈕可用,然後單擊該按鈕。單擊按鈕後,驗證碼將進入服務以進行解決。
js
await page.goto('https://www.google.com/recaptcha/api2/demo')
// 等待具有 CSS 选择器 ".captcha-solver" 的元素可用
await page.waitForSelector('#recaptcha-anchor-label')
// 单击具有指定选择器的元素
await page.click('#recaptcha-anchor-label')
完整代碼示例
js
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://www.google.com/recaptcha/api2/demo')
// 等待具有 CSS 选择器 "#recaptcha-anchor-label" 的元素可用
await page.waitForSelector('#recaptcha-anchor-label')
// 单击具有指定选择器的元素
await page.click('#recaptcha-anchor-label')
})();
这样就完成了使用 Puppeteer 和 Capsolver 扩展程序解决 reCaptcha v2 的过程。如果您需要解决其他验证码,只需为其他验证码复制该教程即可。
Capsolver团队 ?
加入我們
中文代理QQ群:497493756
合規聲明: 本博客提供的信息仅供参考。CapSolver 致力于遵守所有适用的法律和法规。严禁以非法、欺诈或滥用活动使用 CapSolver 网络,任何此类行为将受到调查。我们的验证码解决方案在确保 100% 合規的同时,帮助解决公共数据爬取过程中的验证码难题。我们鼓励负责任地使用我们的服务。如需更多信息,请访问我们的服务条款和隱私政策。
更多

最佳Google Chrome扩展和Mozilla Firefox扩展自动解决验证码
通過使用爲谷歌浏覽器和火狐浏覽器設計的一些擴展程序,我們可以輕松實現這一過程的自動化,從而節省寶貴的時間和精力

Emma Foster
17-Jun-2024

Chrome Captcha自动解决器,如何下载CapSolver
在数字时代,CAPTCHA(Completely Automated Public Turing tests to tell Computers and Humans Apart,完全自动区分计算机和人类的公共图灵测试)作为一项重要的安全措施,用于保护网站免受自动机器人的攻击。然而,手动解决CAPTCHA可能会耗费时间并令人沮丧...

Emma Foster
23-Feb-2024
如何使用CapSolver的谷歌浏覽器插件識別任何驗證碼
本文将解释如何在不同的浏览器中下载和安装 Capsolver 扩展程序,以及其特性、定价等。

Emma Foster
24-Jul-2023

如何使用 Puppeteer 和 Capsolver 扩展程序谷歌插件解决 reCaptcha
在这篇博客中,我们将解释如何使用 Capsolver 扩展程序设置 Puppeteer JS,以解决 reCaptcha v2,当然,您也可以将此方法应用于所有其他类型的验证码。

Emma Foster
24-Jul-2023

如何使用CapSolver在Puppeteer中解決驗證碼
本教程将指导您使用CapSolver在Puppeteer中解决Google reCaptcha的过程。 CapSolver是一种验证码解决服务,可以帮助您解决验证码。

Emma Foster
18-Jul-2023