我在获取元素中列出的文本时遇到了问题。我认为我做得对,但我一直收到错误。这就是我想要得到的元素。任何帮助都是最好的。无法链接网站,因为您必须登录才能访问此页面。
<p><span class="query-player_current">1</span>
/
<span class="query-player_max">32</span></p>(正在尝试获取"1“和"32")^
这是我拥有的代码。
const result = await page.evaluate (() => {
let playerCount = document.querySelector('query-player_current').innerText;
let playerCountMax = document.querySelector('query-player_max').innerText;
return {
playerCount,
playerCountMax
}
})这是我得到的错误。
Error: Evaluation failed: TypeError: Cannot read property 'innerText' of null
at __puppeteer_evaluation_script__:2:73
at ExecutionContext._evaluateInternal (C:\Users\logan\Desktop\GamerBot\node_modules\puppeteer\lib\ExecutionContext.js:122:13)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async ExecutionContext.evaluate (C:\Users\logan\Desktop\GamerBot\node_modules\puppeteer\lib\ExecutionContext.js:48:12)
at async downloadLog (C:\Users\logan\Desktop\GamerBot\commands\test2.js:56:20)
at async Object.module.exports.run (C:\Users\logan\Desktop\GamerBot\commands\test2.js:15:3)
-- ASYNC --
at ExecutionContext.<anonymous> (C:\Users\logan\Desktop\GamerBot\node_modules\puppeteer\lib\helper.js:111:15)
at DOMWorld.evaluate (C:\Users\logan\Desktop\GamerBot\node_modules\puppeteer\lib\DOMWorld.js:112:20)
-- ASYNC --
at Frame.<anonymous> (C:\Users\logan\Desktop\GamerBot\node_modules\puppeteer\lib\helper.js:111:15)
at Page.evaluate (C:\Users\logan\Desktop\GamerBot\node_modules\puppeteer\lib\Page.js:860:43)
at Page.<anonymous> (C:\Users\logan\Desktop\GamerBot\node_modules\puppeteer\lib\helper.js:112:23)
at downloadLog (C:\Users\logan\Desktop\GamerBot\commands\test2.js:56:31)
at async Object.module.exports.run (C:\Users\logan\Desktop\GamerBot\commands\test2.js:15:3)```发布于 2020-04-02 03:23:12
你必须使用'.‘作为前缀,如果您在查询中使用类名。试一试
document.querySelector('.query-player_current')
document.querySelector('.query-player_max')发布于 2020-04-02 07:38:29
我把它弄好了。现在我试着做
let whitlist = document.querySelector('.form-control').innerText;
return {
whitlist
}
});它不会起作用的。它
Error: Evaluation failed: TypeError: Cannot read property 'innerText' of null元素如下所示
<textarea class="form-control" data-toggle="tooltip" data-container=".settings-form" data-html="true" data-placement="bottom" title="" id="form_base_whitelist" name="form[base][whitelist]" data-original-title="">
Nasty CEO
</textarea>https://stackoverflow.com/questions/60978714
复制相似问题