возникли проблемы при получении данных от кукловода .innertext js - PullRequest
0 голосов
/ 01 апреля 2020

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

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

Ответы [ 2 ]

1 голос
/ 01 апреля 2020

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

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

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

0 голосов
/ 02 апреля 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>
...