roo*_*eih 3 javascript node.js puppeteer
我无法使用 Puppeteer 验证页面上是否存在 div,而且我不知道为什么...我想使用以下代码在页面上确定验证码的范围:
puppeteer
.launch(options)
.then(async (browser) => {
const page = await browser.newPage();
await page.setViewport({ width: 1280, height: 720 });
console.log("[+] Connecting...");
await page.goto("https://www.google.com/recaptcha/api2/demo");
console.log("[+] Connected");
page.waitForNavigation()
if (await page.$('div.recaptcha-checkbox-border') !== null)
console.log('[+] Resolving captcha');
})
.catch((err) => {
console.log(err);
});
Run Code Online (Sandbox Code Playgroud)
但我的 if 总是假的,我不知道为什么。
以下是手动确定范围的元素的屏幕截图:
这个脚本应该可以工作
'use strict';
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ headless : false});
const page = await browser.newPage();
console.log("Opening page");
await page.goto('https://www.google.com/recaptcha/api2/demo');
console.log("Opened page");
const frame = await page.frames().find(f => f.name().startsWith("a-"));
await frame.waitForSelector('div.recaptcha-checkbox-border');
console.log("Captcha exists!");
await browser.close();
})();
Run Code Online (Sandbox Code Playgroud)
看来验证码位于始终以 开头的 iframe 内name=a-(但是我无法通过有限的测试确认这一点)
您首先需要获取 iframe,然后在 iframe 加载后等待选择器。这是输出,尝试更改 iframe 名称或选择器名称以查看失败。
| 归档时间: |
|
| 查看次数: |
3515 次 |
| 最近记录: |