node.js - 无头木偶的Node.js问题:True:“评估失败:TypeError:无法读取属性'querySelectorAll' of null”
问题描述
我的代码与 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”,但我什么也没得到,我真的不明白。你知道问题是什么吗?
解决方案
推荐阅读
- c - fork() 如何产生不同的结果?
- node.js - 单击时推送选定的选项
- typescript - 错误:HTTP 错误:400,请求包含无效参数。运行 firebase 功能时:配置:设置
- python - 如何使用 python 打印学生成绩的最高分和姓名?
- php - 使用无服务器将 Laravel 应用程序部署到 AWS 后的空白页面
- javascript - 将事件单击添加到多个按钮实例
- python - LinAlgError:SVD 未在线性最小二乘 np.linalg.lstsq 中收敛
- reactjs - 无法读取 React 应用程序中未定义的图像
- python - 远程连接上的 VBA Shell
- android - 鼠标位置和绘图在屏幕上未对齐