Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从Puppeter.innertext js获取数据时遇到问题_Javascript_Puppeteer_Innertext - Fatal编程技术网

Javascript 从Puppeter.innertext js获取数据时遇到问题

Javascript 从Puppeter.innertext js获取数据时遇到问题,javascript,puppeteer,innertext,Javascript,Puppeteer,Innertext,我在获取元素中列出的文本时遇到问题。我以为我做得对,但我总是出错。这就是我想要得到的元素。任何帮助都会很好。无法链接网站,因为您必须登录才能访问此页面 <p><span class="query-player_current">1</span> / <span class="query-player_max">32</span></p> 这就是我得到的错误 Error: Evaluation failed: TypeErr

我在获取元素中列出的文本时遇到问题。我以为我做得对,但我总是出错。这就是我想要得到的元素。任何帮助都会很好。无法链接网站,因为您必须登录才能访问此页面

<p><span class="query-player_current">1</span>
/
<span class="query-player_max">32</span></p>
这就是我得到的错误

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)```
错误:评估失败:TypeError:无法读取null的属性“innerText”
在(木偶演员)(评估)(剧本):2:73
在ExecutionContext.\u evaluateInternal(C:\Users\logan\Desktop\GamerBot\node\u modules\puppeter\lib\ExecutionContext.js:122:13)
在处理和拒绝时(内部/process/task_queues.js:97:5)
在async ExecutionContext.evaluate(C:\Users\logan\Desktop\GamerBot\node\u modules\puppeter\lib\ExecutionContext.js:48:12)
异步下载日志(C:\Users\logan\Desktop\GamerBot\commands\test2.js:56:20)
在async Object.module.exports.run(C:\Users\logan\Desktop\GamerBot\commands\test2.js:15:3)
--异步的--
在执行上下文中。(C:\Users\logan\Desktop\GamerBot\node\u modules\puppeter\lib\helper.js:111:15)
在DOMWorld.evaluate(C:\Users\logan\Desktop\GamerBot\node\u modules\puppeter\lib\DOMWorld.js:112:20)
--异步的--
在画面上。(C:\Users\logan\Desktop\GamerBot\node\u modules\puppeter\lib\helper.js:111:15)
在Page.evaluate(C:\Users\logan\Desktop\GamerBot\node\u modules\puppeter\lib\Page.js:860:43)
在第页。(C:\Users\logan\Desktop\GamerBot\node\u modules\puppeter\lib\helper.js:112:23)
下载日志(C:\Users\logan\Desktop\GamerBot\commands\test2.js:56:31)
在async Object.module.exports.run(C:\Users\logan\Desktop\GamerBot\commands\test2.js:15:3)```

如果在查询中使用类名,则必须使用“.”作为前缀。 试一试


我让它工作起来了。现在我正在努力

        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>

讨厌的CEO

您可以尝试添加一些waitForSelector吗?因为您使用类进行查询,所以需要添加一个点状的
document.querySelector('.query-player_current')
您忘记了在querySelector中的选择器名称之前添加
,这就是它返回null.hmm的原因。现在我不能记录了?我尝试了console.log(value),但没有成功。说价值是没有定义的。
 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>