最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - solving recaptcha without a form submit button click ( uses callback ) - Stack Overflow

programmeradmin0浏览0评论

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('', {timeout: 60000})
            .catch(function (error) {
                throw new Error('TimeoutBrows');
            });

        await page.waitForSelector('input[name="url"]');
        await page.type('input[name="url"]', 'example' , {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();

    }
}

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.', {timeout: 60000})
            .catch(function (error) {
                throw new Error('TimeoutBrows');
            });

        await page.waitForSelector('input[name="url"]');
        await page.type('input[name="url"]', 'example.' , {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();

    }
}
Share Improve this question edited Mar 19, 2021 at 20:54 DisappointedByUnaccountableMod 6,8464 gold badges20 silver badges23 bronze badges asked Apr 24, 2020 at 18:14 hretichretic 1,1159 gold badges43 silver badges88 bronze badges 1
  • I am not sure how you are bypassing the reCAPTCHA, but if having this fully automated is not a "must", you can always interact with the browser by using the 'headless' parameter: const browser = await puppeteer.launch({ headless: false }) That way, you can fill it manually and then continue with your scraping script. – charly rl Commented Apr 24, 2020 at 21:19
Add a ment  | 

1 Answer 1

Reset to default 5

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);
发布评论

评论列表(0)

  1. 暂无评论