Skip to content
Advertisement

solving recaptcha without a form submit/ button click ( uses callback )

im trying to solve a recaptcha from a website im trying to scrape

usually the way it works is , captcha is inside a form , i’ll send the captcha data to a solving captcha api (im using DBC) , they return a token

i put the token inside captcha input (#g-recaptcha-response) and even tho the green check doesn’t show up when i submit the form it will get accepted

but this website automatically shows the information i want to scrape as soon as captcha is solved in another way when the green check of captcha shows up , the page get updated with new information

so my question is when i put the token inside captcha input is there any way to trigger captcha solved event (or whatever happens when green check shows up .. im guessing some sort of callback ) without submitting the form ?

edit :

by exploring recaptcha configuration exploring i found this

___grecaptcha_cfg.clients[0].L.L.callback

which points to this

function verifyCallback(e)

but im not sure how to invoke it

async function init_puppeteer() {

    const global_browser = await puppeteer.launch({headless: false     , slowMo : 10 ,  args: ['--no-sandbox', '--disable-setuid-sandbox' , ]});
    const page = await global_browser.newPage();
    await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36');
    await page.setViewport({width: 1200, height: 1500});

    try {


        await page.goto('https://example.com', {timeout: 60000})
            .catch(function (error) {
                throw new Error('TimeoutBrows');
            });

        await page.waitForSelector('input[name="url"]');
        await page.type('input[name="url"]', 'example.com' , {delay: 10})
        await page.click('button.css-117i75i-button');
        await page.waitForSelector('#g-recaptcha' ,{visible : true });
        const datakey = await page.$eval('#g-recaptcha' , el => el.getAttribute('data-sitekey'));
        const cap = await solvecaptcha(datakey ,page.url() );

        await page.$eval('#g-recaptcha-response', (el  , cap ) => el.value = cap , cap );
        console.log('done!');


    }
    catch(e)
    {
        console.log('--------ERRRO--------------------------');
        console.log(e);
        await  page.close();

    }
}

Advertisement

Answer

i found the answer , just in case anyone has this problem just in your browser console play with this object ___grecaptcha_cfg to find the callback mine was here

___grecaptcha_cfg.clients[0].L.L.callback

but it can have different structure for other websites

so basically after i recived the token and put it in the #g-recaptcha-response` i called this function and passed the token as argument

    let js = `___grecaptcha_cfg.clients[0].L.L.callback("${cap}")`;
    await page.evaluate(js);
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement