小编Noa*_*oah的帖子

Puppeteer:获取内部HTML

有没有人知道如何获取元素的innerHTML或文本.甚至更好; 如何单击具有特定innerHTML的元素.这是如何使用普通的javascript:

var found = false
$(selector).each(function() {
                if (found) return;
                else if ($(this).text().replace(/[^0-9]/g, '') === '5' {
                    $(this).trigger('click');
                    found = true
                }
Run Code Online (Sandbox Code Playgroud)

在此先感谢您的帮助!

javascript selenium webautomation node.js puppeteer

14
推荐指数
4
解决办法
2万
查看次数

node.js中的SSL证书错误

我和木偶戏有问题了.所以我想要做的是启动一个网站并登录.但是,此网站尝试加载由于其不安全而被阻止的资源.运行代码后,我收到此错误消息,代码停止运行:

(node:11684) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: SSL Certificate error: ERR_CERT_COMMON_NAME_INVALID
(node:11684) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Run Code Online (Sandbox Code Playgroud)

我的代码:

'use strict';

const puppeteer = require('puppeteer');

async function Login(username, password){
  const browser = await puppeteer.launch({
    headless: false
  });
  const page = await browser.newPage();
  await page.goto('https://shop.adidas.ae/en/customer/account/login', {waitUntil: 'networkidle'});
  /*await page.type(username);
  await page.focus('#pass');
  await page.type(password);
  await page.click('#send2');*/
  await browser.close();
} …
Run Code Online (Sandbox Code Playgroud)

javascript ssl webautomation node.js puppeteer

3
推荐指数
1
解决办法
1687
查看次数

页面评估的返回值(puppeteer,asnyc 编程)

我有以下问题:我在 puppeteer 中有一个页面评估,其中包括不同步的部分。我想将异步部分的值返回给 puppeteer,但是,它只是返回 undefined 而不等待 Promise 解决。有没有人如何解决问题?

我的示例代码:

const puppeteer = require('puppeteer');
async function testing(num) {
  const browser = await puppeteer.launch({
    headless: false,
    ignoreHTTPSErrors: true
  });
  const page = await browser.newPage();
  const evaluating = await page.evaluate((num) => {
    //some synchrnous stuff (declaring some variablesand so on...)
    function lookForNumber(num) {
      if (num > 2) {
        var asyncstuff = setTimeout(function () {
          if (num > 10) {
            console.log('number is greater than 9');
            var whatIwantToRetrun = 'ten';
            return Promise.resolve(whatIwantToRetrun);
            //return here
          } …
Run Code Online (Sandbox Code Playgroud)

javascript asynchronous evaluate node.js puppeteer

3
推荐指数
1
解决办法
5703
查看次数