Puppeteer: Get inner HTML

2020-02-10 12:46发布

does anybody know how to get the innerHTML or text of an element. Or even better; how to click an element with a specific innerHTML. This is how it would work with normal javascript:

var found = false
$(selector).each(function() {
                if (found) return;
                else if ($(this).text().replace(/[^0-9]/g, '') === '5' {
                    $(this).trigger('click');
                    found = true
                }

Thanks in advance for any help!

7条回答
淡お忘
2楼-- · 2020-02-10 13:35

You can simply write as below. (no need await sentence in the last part) const center = await page.$eval('h2.font-34.uppercase > strong', e => e.innerHTML);

查看更多
登录 后发表回答