微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Node.js 木偶无头问题:True:“评估失败:TypeError:无法读取 null 的属性 'querySelectorAll'”

如何解决Node.js 木偶无头问题:True:“评估失败:TypeError:无法读取 null 的属性 'querySelectorAll'”

我的代码与 headless false 配合得很好,但是当我将其更改为 true 时,我收到此错误

(node:92024) UnhandledPromiseRejectionWarning: Error: Evaluation Failed: TypeError: Cannot read property 'querySelectorAll' of null
    at __puppeteer_evaluation_script__:7:17
    at ExecutionContext._evaluateInternal (C:\wamp64\www\scrappingWithNodejs\testdiscordBot\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:221:19)
    at processticksAndRejections (internal/process/task_queues.js:95:5)
    at async ExecutionContext.evaluate (C:\wamp64\www\scrappingWithNodejs\testdiscordBot\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:110:16)   
    at async getAllInfos (C:\wamp64\www\scrappingWithNodejs\testdiscordBot\index.js:28:12)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:92024) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block,or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection,use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:92024) [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.

我的代码

async function getAllInfos() {
  const browser = await puppeteer.launch({ headless: true }); 
  const page = await browser.newPage();
  page.setDefaultNavigationTimeout(0);
  await page.goto(`https://www.japanread.cc/`,{
    waitUntil: ["load","domcontentloaded","networkidle0","networkidle2"],}); //se rendre sur une page
    let trs = [];

    trs = tbody.querySelectorAll("tr");//the error is here

我试着放了showMo,在"waitUntil"里放了几样东西,但是我什么也没得到,我真的不明白。 你知道问题出在哪里吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。