How do I save a Value to a variable using puppeteer

Xaccer

New member
Hi im trying to automatically solve captchas using 2captcha and puppeteer and I'm having trouble saving the value of the data-sitekey to a variable I've never used javascript or puppeteer before so any pointers would be helpful

What I'm Trying to get

<div id="g-recaptcha" class="g-recaptcha" data-sitekey="6LfjzmQUAAAAAJxTOcx3vYq3hroeYczGfDPU-NlX"></div>

What I've Tried
Code:
const result = await page.evaluate(() => {
    return result.querySelectorAll('#g-recaptcha');
  })
  console.log(result);
 

RealB

New member
You are using result.querySelectorAll instead of document.querySelectorAll. It should be:
Code:
const result = await page.evaluate(() => {
    return document.querySelectorAll('#g-recaptcha');
})
console.log(result.dataset.sitekey);

Or better yet do:
Code:
const result = await page.evaluate(() => {
    return document.getElementById('g-recaptcha').getAttribute('data-sitekey');
})
console.log(result);