возникли проблемы с получением данных от puppeteer .innertext js

у меня проблемы с получением текста, указанного в элементе. Я думал, что сделал это правильно, но я продолжаю получать ошибки. Это элемент, который я пытаюсь получить. Любая помощь будет здорово. Не могу дать ссылку на сайт, потому что для доступа к этой странице необходимо авторизоваться.

<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)```

person Nasty Game Nation    schedule 01.04.2020    source источник
comment
Можете ли вы попробовать добавить какой-нибудь waitForSelector?   -  person hardkoded    schedule 01.04.2020
comment
Поскольку вы используете класс для запроса, вам нужно добавить точку, например document.querySelector('.query-player_current')   -  person Sam R.    schedule 01.04.2020
comment
Вы забыли добавить . перед именем селектора в querySelector, и поэтому он возвращает значение null.   -  person Abrar Hossain    schedule 01.04.2020
comment
хм хорошо. теперь я не могу войти в консоль? я пробовал console.log(значение), но не работал. значение слова не определено.   -  person Nasty Game Nation    schedule 01.04.2020


Ответы (2)


Вы должны использовать '.' в качестве префикса, если вы используете имена классов в запросе. пытаться

 document.querySelector('.query-player_current')
 document.querySelector('.query-player_max')

Документация

person Vimal    schedule 01.04.2020

у меня это работает. теперь я пытаюсь сделать

        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>
person Nasty Game Nation    schedule 01.04.2020