Puppeteer:与 waitForSelector 处理程序中的 dom 交互

Puppeteer: interact with dom in waitForSelector handler

当我使用 puppeteer js 网络爬虫时,在 waitForSelector 处理程序中我可以毫无问题地使用 console.log:

page
  .waitForSelector('input[value=update]')
  .then(() => {
    console.log('this is');
    console.log('it');
  });

但是我想和DOM交互的时候出错了:

page
  .waitForSelector('input[value=update]')
  .then(() => {
    const inputValidate = await page.$('input[value=update]');
  });

此代码触发此错误:

const inputValidate = await page.$('input[value=update]'); ^^^^

SyntaxError: Unexpected identifier at createScript (vm.js:74:10) at Object.runInThisContext (vm.js:116:10) at Module._compile (module.js:537:28) at Object.Module._extensions..js (module.js:584:10) at Module.load (module.js:507:32) at tryModuleLoad (module.js:470:12) at Function.Module._load (module.js:462:3) at Function.Module.runMain (module.js:609:10) at startup (bootstrap_node.js:158:16) at bootstrap_node.js:598:3

你知道如何在 waitForSelector 处理程序中与 DOM 交互而不触发错误吗?

await page
  .waitForSelector('input[value=update]')
  .then(async() => {
    const inputValidate = await page.$('input[value=update]');
  });