Reputation: 11
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
const result = await page.evaluate(() => {
return result.querySelectorAll('#g-recaptcha');
})
console.log(result);
Upvotes: 0
Views: 636
Reputation: 8683
You are using result.querySelectorAll
instead of document.querySelectorAll
. It should be:
const result = await page.evaluate(() => {
return document.querySelectorAll('#g-recaptcha');
})
console.log(result.dataset.sitekey);
Or better yet do:
const result = await page.evaluate(() => {
return document.getElementById('g-recaptcha').getAttribute('data-sitekey');
})
console.log(result);
Upvotes: 3