Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// usage: let res = findRecaptchaClients()
// console.log(res)
// returns an array of objects with recaptcha parameters for each implementation found on the page
function findRecaptchaClients() {
// eslint-disable-next-line camelcase
if (typeof (___grecaptcha_cfg) !== 'undefined') {
// eslint-disable-next-line camelcase, no-undef
return Object.entries(___grecaptcha_cfg.clients).map(([cid, client]) => {
const data = { id: cid, version: cid >= 10000 ? 'V3' : 'V2' };
const objects = Object.entries(client).filter(([_, value]) => value && typeof value === 'object');
objects.forEach(([toplevelKey, toplevel]) => {
const found = Object.entries(toplevel).find(([_, value]) => (
value && typeof value === 'object' && 'sitekey' in value && 'size' in value
));
if (found) {
const [sublevelKey, sublevel] = found;
data.sitekey = sublevel.sitekey;
const callbackKey = data.version === 'V2' ? 'callback' : 'promise-callback';
const callback = sublevel[callbackKey];
if (!callback) {
data.callback = null;
data.function = null;
} else {
data.function = callback;
const keys = [cid, toplevelKey, sublevelKey, callbackKey].map((key) => `['${key}']`).join('');
data.callback = `___grecaptcha_cfg.clients${keys}`;
}
}
});
return data;
});
}
return [];
}
@khaelou

This comment has been minimized.

Copy link

@khaelou khaelou commented Jun 12, 2020

Thanks, much appreciated 👍

@hdsouza

This comment has been minimized.

Copy link

@hdsouza hdsouza commented Oct 28, 2020

When this script is run in the console (Chrome - Dev Tools) it returns undefined. Is it still working?

@khaelou

This comment has been minimized.

Copy link

@khaelou khaelou commented Oct 29, 2020

@hdsouza try using "___grecaptcha_cfg.clients[0]" in console to find the captcha

@hdsouza

This comment has been minimized.

Copy link

@hdsouza hdsouza commented Oct 29, 2020

Thanks @khaelou.

Yes, I opened the site in Firefox and did an inspect element
In the console if I type "___grecaptcha_cfg.clients". I see 2 clients. Which one do i select? 0 or 100000

image

If I select 0 then.. Is this the correct path.. "___grecaptcha_cfg.clients[0].A.A." ..or do i need to go into some of the other letters below, like G, N etc. I was going with A.A as I see that it has the same sitekey value as I would need to use when I would request for the captcha response.

image

@khaelou

This comment has been minimized.

Copy link

@khaelou khaelou commented Oct 29, 2020

@hdsouza Yes always use ___grecaptcha_cfg.clients[0], from previous experience please remember that the Object letter may change over time. For example ___grecaptcha_cfg.clients[0].A.sitekey may become ___grecaptcha_cfg.clients[0].K.sitekey another day. So again, it'll always be the object which contains the sitekey.

@kratzky

This comment has been minimized.

Copy link

@kratzky kratzky commented Nov 2, 2020

Thanks @khaelou.

Yes, I opened the site in Firefox and did an inspect element
In the console if I type "___grecaptcha_cfg.clients". I see 2 clients. Which one do i select? 0 or 100000

image

If I select 0 then.. Is this the correct path.. "___grecaptcha_cfg.clients[0].A.A." ..or do i need to go into some of the other letters below, like G, N etc. I was going with A.A as I see that it has the same sitekey value as I would need to use when I would request for the captcha response.

image

In most cases:
[0] is V2/V2 invisible
[100000] is V3

and even in really rare cases there are multiple implementations of each version with indexes like [1], [2] or [100001], [100002]

@hdsouza

This comment has been minimized.

Copy link

@hdsouza hdsouza commented Nov 2, 2020

So what should the call back in this case: "___grecaptcha_cfg.clients[0].A.A.callback(CapthcaResponse) ?

@khaelou

This comment has been minimized.

Copy link

@khaelou khaelou commented Nov 2, 2020

@hdsouza ___grecaptcha_cfg.clients[0].A.A.callback(CapthcaResponse) is correct way to call callback in your case

@hdsouza

This comment has been minimized.

Copy link

@hdsouza hdsouza commented Nov 3, 2020

@khaelou I have tried that command from Firefox - devtools - console and it does not send the response across. There is no activity on page to signify that the command did anything. Do I need to specify the name of the callback function "bound " somehow?

@khaelou

This comment has been minimized.

Copy link

@khaelou khaelou commented Nov 3, 2020

@hdsouza That's odd, yet I'm not sure about Firefox since I've been using Chrome. Try running from Chrome Dev Tools Console and see if that makes a difference. The name of callback or what goes in the '' of the callback() function is the solved token key that is generated from 2captcha.com

@hdsouza

This comment has been minimized.

Copy link

@hdsouza hdsouza commented Nov 6, 2020

Thanks @khaelou . I just realized it was working all along. The callback command was being sent correctly but I was looking for a check-mark of captcha acceptance which I was not seeing, but when I just tried clicking on the login button, it went right through. Thanks for prodding me in the right direction :) .. That being said, is there a command that will validate that the captcha has been accepted.. something like grecaptcha.getResponse (I realize its not relevant to the main topic).

@khaelou

This comment has been minimized.

Copy link

@khaelou khaelou commented Nov 16, 2020

@hdsouza Yes, yet it isn't exactly a command. You should refer to the documentation of your provided captcha solving service (2captcha) which usually provide endpoints for verification/error-handling.

@Kukunin

This comment has been minimized.

Copy link

@Kukunin Kukunin commented Jan 13, 2021

Thank you for the code. I modified it to avoid evals:

function findRecaptchaClients() {
  // eslint-disable-next-line camelcase
  if (typeof (___grecaptcha_cfg) !== 'undefined') {
    // eslint-disable-next-line camelcase, no-undef
    return Object.entries(___grecaptcha_cfg.clients).map(([cid, client]) => {
      const data = { id: cid, version: cid >= 10000 ? 'V3' : 'V2' };
      const objects = Object.entries(client).filter(([_, value]) => value && typeof value === 'object');

      objects.forEach(([toplevelKey, toplevel]) => {
        const found = Object.entries(toplevel).find(([_, value]) => (
          value && typeof value === 'object' && 'sitekey' in value && 'size' in value
        ));
        if (found) {
          const [sublevelKey, sublevel] = found;

          data.sitekey = sublevel.sitekey;
          const callbackKey = data.version === 'V2' ? 'callback' : 'promise-callback';
          const callback = sublevel[callbackKey];
          if (!callback) {
            data.callback = null;
            data.function = null;
          } else {
            data.function = callback;
            const keys = [cid, toplevelKey, sublevelKey, callbackKey].map((key) => `['${key}']`).join('');
            data.callback = `___grecaptcha_cfg.clients${keys}`;
          }
        }
      });
      return data;
    });
  }
  return [];
}
@2captcha

This comment has been minimized.

Copy link
Owner Author

@2captcha 2captcha commented Jan 13, 2021

Thank you for the code. I modified it to avoid evals:

Thank you, @Kukunin!
Updated the gist to your version which is really good.

@adreesm102

This comment has been minimized.

Copy link

@adreesm102 adreesm102 commented Jan 16, 2021

Hi here is my website https://web.sbcounty.gov/sheriff/bookingsearch/bookingsearch.aspx after submit booking number 2101340001 I will get a callback Recaptcha. I tried a lot to call that Recaptcha but unfortunately unsuccessful. I have not got anything in inspect>console after typing the command. can you please help how can I call that callback function. I am doing it using node js

@2captcha

This comment has been minimized.

Copy link
Owner Author

@2captcha 2captcha commented Jan 16, 2021

Hi here is my website https://web.sbcounty.gov/sheriff/bookingsearch/bookingsearch.aspx after submit booking number 2101340001 I will get a callback Recaptcha. I tried a lot to call that Recaptcha but unfortunately unsuccessful. I have not got anything in inspect>console after typing the command. can you please help how can I call that callback function. I am doing it using node js

@adreesm102 looks like you are not following the instruction from the comment

screenshot

@hdsouza

This comment has been minimized.

Copy link

@hdsouza hdsouza commented Jan 16, 2021

@adreesm102 Try the commands in JavaScript one line at a time and identify on which line the errors occurs.

@adreesm102

This comment has been minimized.

Copy link

@adreesm102 adreesm102 commented Jan 16, 2021

@2captcha thanks its clear. Now I am facing the issue that I got the response from 2captcha but when I execute the callback ___grecaptcha_cfg.clients[0].P.P.callback('${response}') It does not work. I want to render the page to next when Recaptcha is resolved.So can u help me in that way. I am using Node Js puppeteer

@hdsouza

This comment has been minimized.

Copy link

@hdsouza hdsouza commented Jan 16, 2021

Your ___grecaptcha_cfg.clients[0].P.P.callback is correct. I believe the RESPONSE is also correct, but the problem doing it this way is that the page will not tell you that the CAPTCHA has been accepted or not. The page needs an OK button to click on, on the page,
So after you have executed the script, you click on the OK button and that should take it.
Since there is no OK button on the page, that will pose a problem.

You can try to add an OK button to the page via script... as in this video https://www.youtube.com/watch?v=zOmhDxRqX18 -- @3:34 .
Then execute the callback and click on the OK button.
Not sure if this is even possible, but you can try.

@adreesm102

This comment has been minimized.

Copy link

@adreesm102 adreesm102 commented Jan 16, 2021

Thanks, @hdsouza but it not work.

@adreesm102

This comment has been minimized.

Copy link

@adreesm102 adreesm102 commented Jan 17, 2021

(https://user-images.githubusercontent.com/70963992/104833483-b8a64d80-58ba-11eb-9872-3cf8e5381f96.JPG)
can you please guid me Is I am calling right callback
driver.execute('___grecaptcha_cfg.clients[0].P.P.callback({})'.format(token))

@hdsouza

This comment has been minimized.

Copy link

@hdsouza hdsouza commented Jan 17, 2021

Try using webmaster tools with the google browser.
With that, the command I use is
const CapthcaResponse = "CAPTCHA_RESPONSE_RECEIVED";
___grecaptcha_cfg.clients[0].P.P.callback(CapthcaResponse);

@weiitezhu

This comment has been minimized.

Copy link

@weiitezhu weiitezhu commented Jan 18, 2021

I couldn't find the last callback function I needed
image
image

@weiitezhu

This comment has been minimized.

Copy link

@weiitezhu weiitezhu commented Jan 18, 2021

I found a possible one but it always gets an error when I call it
image
image

@Vyprath

This comment has been minimized.

Copy link

@Vyprath Vyprath commented Jan 18, 2021

image
https://account.oneplus.com/signin/

I cannot for the life of me find any callback functions in the code. Is there any?

@2captcha

This comment has been minimized.

Copy link
Owner Author

@2captcha 2captcha commented Jan 18, 2021

@Vyprath

This comment has been minimized.

Copy link

@Vyprath Vyprath commented Jan 18, 2021

@Vyprath
image

    result = solver.recaptcha(
        sitekey='6LcXjQcUAAAAANKDft8a25E8PRogqCPKENK2LCnv', url=driver.current_url)
    TOKEN_FROM_2CAPTCHA = result['code']
    driver.execute_script(
        f'document.getElementById("g-recaptcha-response").innerHTML="{TOKEN_FROM_2CAPTCHA}";')
    print("Executed driver script:")
    driver.execute_script(
        "___grecaptcha_cfg.clients['0']['P']['P']['callback'];"
    )

    print("Submitted function")

This is how I am doing it but it still isn't solving the captcha in my screen atleast.
image

@2captcha

This comment has been minimized.

Copy link
Owner Author

@2captcha 2captcha commented Jan 18, 2021

@weiitezhu

I found a possible one but it always gets an error when I call it

You found a wrong one.
And at least there's no callback defined inside grecaptcha.render so if the captcha is rendered from the code you found then there's no callback.
Please read the recaptcha docs to find how the callback can be defined if you are not able to use the script from the gist for some reason. And keep in mind that callback is optional.

@2captcha

This comment has been minimized.

Copy link
Owner Author

@2captcha 2captcha commented Jan 18, 2021

@Vyprath

    result = solver.recaptcha(
        sitekey='6LcXjQcUAAAAANKDft8a25E8PRogqCPKENK2LCnv', url=driver.current_url)
    TOKEN_FROM_2CAPTCHA = result['code']
    driver.execute_script(
        f'document.getElementById("g-recaptcha-response").innerHTML="{TOKEN_FROM_2CAPTCHA}";')
    print("Executed driver script:")
    driver.execute_script(
        "___grecaptcha_cfg.clients['0']['P']['P']['callback'];"
    )

    print("Submitted function")

This is how I am doing it but it still isn't solving the captcha in my screen atleast.

Try to do everything in the browser console and only then try to repeat the same with Selenium or any other automation tool. That's the first rule everyone should follow.

And yep, your call here is incorrect:

 driver.execute_script(
        "___grecaptcha_cfg.clients['0']['P']['P']['callback'];"
    )

To call a function in JavaScript you must add brackets. It is made like this:

myFunctionName(argument)
myObject.function(arg1, arg2)

Please learn some JavaScript basics if you are going to deal with web automation 😄

@Vyprath

This comment has been minimized.

Copy link

@Vyprath Vyprath commented Jan 18, 2021

Please learn some JavaScript basics if you are going to deal with web automation 😄

For some reason I didn't think that was a function call. Extremely sorry. Everything works now! Thank you 2captcha!

@chwba

This comment has been minimized.

Copy link

@chwba chwba commented Jan 18, 2021

Question: For this website: https://cracked.to/member.php?action=login I paste captcha solution in: 'document.getElementById("g-recaptcha-response").innerHTML = solution like so. When I click Login it asks me to solve the captcha again, can you hint me how to properly submit the solution? (Using the script there is no callback function found)

image

@adreesm102

This comment has been minimized.

Copy link

@adreesm102 adreesm102 commented Jan 18, 2021

@Vyprath

This comment has been minimized.

Copy link

@Vyprath Vyprath commented Jan 18, 2021

Can you please share detail how you solved callback function

On Mon, Jan 18, 2021, 6:41 PM Pranav @.***> wrote: @Vyprath commented on this gist. ------------------------------ Please learn some JavaScript basics if you are going to deal with web automation 😄 For some reason I didn't think that was a function call. Extremely sorry. Everything works now! Thank you 2captcha! — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://gist.github.com/2ee70fa1130e756e1693a5d4be4d8c70#gistcomment-3597959, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQ5NGGFZSKTC7SRO7ZISVC3S2Q3BZANCNFSM4N34BUWQ .

I still haven't fully figured it out myself too. I just added () to the end. But I am facing an error ("Captcha Invalid"). Although I think it is because my IP is now flagged.

@chwba

This comment has been minimized.

Copy link

@chwba chwba commented Jan 18, 2021

Question: For this website: https://cracked.to/member.php?action=login I paste captcha solution in: 'document.getElementById("g-recaptcha-response").innerHTML = solution like so. When I click Login it asks me to solve the captcha again, can you hint me how to properly submit the solution? (Using the script there is no callback function found)

image

Anyone got an idea?

@kratzky

This comment has been minimized.

Copy link

@kratzky kratzky commented Jan 18, 2021

@chwba
Try this:

document.querySelector('#g-recaptcha-response').innerText='token_string_here'
document['getElementsByClassName']('member-full')[0]['submit']()
@chwba

This comment has been minimized.

Copy link

@chwba chwba commented Jan 18, 2021

document['getElementsByClassName']('member-full')[0]['submit']()

Nice, that actually pulled it off, how did you find that out? Is there something one could add to the script to figure out this kind of submitting?

Because on https://www.epicnpc.com after clicking "Log in", there is a captcha as well and there this method doesnt work, it fails with:
Uncaught TypeError: document.getElementsByClassName(...)[0] is undefined

Note: Previously I had been using this plugin: https://antcpt.com/eng/download/mozilla-firefox.html which was able to do it perfectly on any website, one with good practise in js could probably rip out the required functions, they use for parsing out the submission information but I am only a python developer :)

@kratzky

This comment has been minimized.

Copy link

@kratzky kratzky commented Jan 18, 2021

@chwba just looking on the button's click event listeners
image

And of course it is applicable only to cracked.to.

@adreesm102

This comment has been minimized.

Copy link

@adreesm102 adreesm102 commented Jan 18, 2021

I am resolving Recaptcha for this website. When I enetered booking # 2101340001 I will get recpatcha. I resolved it successfully but when I resolved it manually It render the page next automatically by calling callback function but It is not happen with 2 captcha
recaptcha

@kratzky can you please check and help me.

.

@adreesm102

This comment has been minimized.

@kratzky

This comment has been minimized.

Copy link

@kratzky kratzky commented Jan 18, 2021

https://web.sbcounty.gov/sheriff/bookingsearch/bookingsearch.aspx this is the web URL

didn't tested on my end, but try the following:

  1. Redefine getBooking changing the part where it gets the captcha token:
getBooking = function(token) {

    var mdl = new InmateLocator.mdlInmateStatus;
    mdl.BookNo = document.getElementById("txtBookNo").value; // row.getAttribute("key0");
    mdl.CaptchaResponse = token;
    document.getElementById("spnResults").style.display = "none";
    document.getElementById("divStatus").style.display = "none";
    document.getElementById("divSearch").style.display = "none";
    document.getElementById("spnStatusMessage").innerHTML = "Getting Booking Information ..."
    document.getElementById("spnStatusMessage").style.display = "";
    document.getElementById("spnSearchAgain").style.display = "none";
    document.getElementById("celBooking").innerHTML = mdl.BookNo;
    PageMethods.GetInmateStatus(mdl, displayBooking, displayError, displayTimeout);
    
}
  1. Fill the form with your booking reference
  2. Execute getBooking passing the token into the function argument:
getBooking('captcha_token_string');

Inside getBooking they get the token directly from grecaptcha.getResponse(); call.
In some cases if you can not redefine the parent function you can redefine grecaptcha.getResponse() like:
grecaptcha.getResponse = () => 'captcha_token_string'

@chwba

This comment has been minimized.

Copy link

@chwba chwba commented Jan 18, 2021

@chwba just looking on the button's click event listeners
image

And of course it is applicable only to cracked.to.

Nice, yeah makes sense, I wonder how that plugin of anticaptcha does it because this one seems to literally work anywhere but since I moved away from selenium I cant use plugins anymore and am now on it to implement it all on my own. - If that plugin can do it anywhere, it should be possible to create a generic solution for the submission problem though.

@Doctuh

This comment has been minimized.

Copy link

@Doctuh Doctuh commented Jan 18, 2021

Hey I am trying to complete a captcha using 2captcha. I get the response code back from 2captcha, which is the response they give up solving the captcha. I inject this token into the innerHtml of the hidden field, which is at id="g-recaptcha-response". This all works flawlessly and I confirmed it by checking the innerHtml to see if the token got injected there, it did.

Now I am trying to execute the callback function, which in my case is at:
___grecaptcha_cfg.clients[0].P.P.callback("Here I provide my token for the solved captcha") I execute this javascript code, on the given captcha page.

However this last step returns to me the following error code:

GET https://geo.captcha-delivery.com/captcha/check?cid=84YTH2O0F.uzeP0Fhm-LTGpltPzojt.Jh1phd7GG6Qi.uCL2rd4Z-LiQWxcVF-Fxw6zzXw9-INkdQrYqZEx8kX-~5qHqyT1Nidsux6Yhl5&icid=AHrlqAAAAAMAeRI5aB3ef_YAk04eUg%3D%3D&ccid=null&g-recaptcha-response=03AGdBq26LUVR7GP5vi8hG3FbHu5tmD1DFNuPU6zLne0eeOstvTttQcruZvy-h15ClYoCG7bxangmf0L71qBo3Rx7QdrujpMwlZsroBNL-bVcVeuEN0WjEyotO6RtD2r-Ly8gPLYhj0Ha2wRcP0uiArvQFZGqOIPGXjxnaK2135OiOT7rmbgrtjxnBZEQ6pvKgQxxo-9nFGVsTMODK86a2Zik8rk-Zi_O7tll8uvLnWiiY8yqlwVcJMc1bDDJZK9PE9lvcYJq32Scfpq1dPHZ9ANBpIx_6eQaQYfvWSWtoTuIdW7X9Tko9FTXsAur6zFAlVsNCTJJe6SeeFLvLc4CF27Zv8x3zLDemz8k1nq_UGXV6ApnhzCkfu9imvpRrfTtG5RrScMkMH5pjr6P9SW8ec-vRL4EVCVrw2Vgxmy9scBcryEJEZl6mhrKeAEAB7RYyT-L6g70spFJHyYLNa2ioLBZyRHsSiUQqPnkTj4BP0kl_X3NXpbGnGtQ0CvVCMLWqxEqWnhMvct4R-XRTYsHGAYly8KX4RdRGrqjwF2ZmamwJI2G0psHbBQs&hash=A55FBF4311ED6F1BF9911EB71931D5&ua=Mozilla%2F5.0%20(Windows%20NT%2010.0%3B%20Win64%3B%20x64)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F87.0.4280.141%20Safari%2F537.36&referer=https%3A%2F%2Fwww.footlocker.dk%2Fen%2Fproduct%2Fnike-air-force-1-low-menshoes%2F314102199404.html&parent_url=https%3A%2F%2Fwww.footlocker.dk%2Fen%2Fproduct%2Fnike-air-force-1-low-menshoes%2F314102199404.html&x-forwarded-for=&captchaChallenge=179113579&s=17434 403 (Forbidden)

If someone would mind helping me out? :S
my discord is: doc#5244 (for faster communication if wanted :))

Regards!

@Doctuh

This comment has been minimized.

Copy link

@Doctuh Doctuh commented Jan 18, 2021

Never mind I fixed it, it was wrong token I put into request, awesome!

@chwba

This comment has been minimized.

Copy link

@chwba chwba commented Jan 19, 2021

Any js dev maybe got an idea how to strip out the mechanics from https://antcpt.com/eng/download/mozilla-firefox.html or https://antcpt.com/eng/download/google-chrome-options.html to create a generic solution for the various different captcha submission mechanics, which are hard to figure out for non-js devs? Having a hard time to figure it out for the other various targets (20+)..

@Vyprath

This comment has been minimized.

Copy link

@Vyprath Vyprath commented Jan 23, 2021

Hey, after I do the captcha callback, I get this error.
image

result = solver.recaptcha(sitekey='6LcXjQcUAAAAANKDft8a25E8PRogqCPKENK2LCnv', url=driver.current_url)
TOKEN_FROM_2CAPTCHA = result['code']

driver.execute_script(
    f'document.getElementById("g-recaptcha-response").innerHTML="{TOKEN_FROM_2CAPTCHA}";')
print("Executed driver script:")
sleep(2)
driver.execute_script(
    f"___grecaptcha_cfg.clients['0']['P']['P']['callback']({TOKEN_FROM_2CAPTCHA});"
)

The issue persists when I am trying to log in to the OnePlus website.
I've tried running the code line-by-line on my browser and still nothing seems to work. Am I passing the wrong token to the callback function? I cannot tell. Website URL: https://account.oneplus.com/signin/

@Oleh-Hrebchuk

This comment has been minimized.

Copy link

@Oleh-Hrebchuk Oleh-Hrebchuk commented Jan 25, 2021

import time

import requests
from selenium import webdriver


API_2CAPTCHA = 'your key'
URL_POST_CAPTCHA = 'http://2captcha.com/in.php'
URL_GET_CAPTCHA = 'http://2captcha.com/res.php'


def resolve_captcha(blocked_url):
    options = webdriver.ChromeOptions()
    user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36'
    options.add_argument('user-agent={0}'.format(user_agent))

    options.add_argument("--disable-blink-features")
    options.add_argument("--disable-blink-features=AutomationControlled")
    driver = webdriver.Chrome(chrome_options=options)
    driver.execute_script("return navigator.userAgent")
    for x in range(10):
        if x == 0:
            driver.get(blocked_url)
            time.sleep(5)

        data_site_key = driver.find_element_by_css_selector('.g-recaptcha').get_attribute('data-sitekey')

        response = requests.get(
            'http://2captcha.com/in.php?key={key}&method=userrecaptcha'
            '&googlekey={data_sitekey}&pageurl={site_url}?appear=1&here=now'.
                format(
                key=API_2CAPTCHA,
                data_sitekey=data_site_key,
                site_url=blocked_url
            )
        )
        timeout = 8
        resolved = False
        for i in range(8):
            time.sleep(timeout)
            timeout += 8

            id_message = response.text.split('|')[-1]
            resolved_captcha = requests.get(
                '{}?key={}&action=get&id={}'.format(
                    URL_GET_CAPTCHA,
                    API_2CAPTCHA,
                    id_message
                )
            )
            resolved_token = resolved_captcha.text.split('|')

            if resolved_token[0] == 'OK':
                resolved = resolved_token[-1]
                print(resolved)
                break

        res = f'handleCaptcha("{resolved}")'
        driver.execute_script(res)

        if driver.current_url != blocked_url:
            break

resolve_captcha('https://www.walmart.com/blocked?url=L2dyb2NlcnkvdjQvYXBpL3Byb2R1Y3RzL3NlYXJjaD9jb3VudD02MCZmaWx0ZXI9Z2hzX2JyYW5kflNpZXRlJTIwRmFtaWx5JTIwRm9vZHMmb2Zmc2V0PTAmcGFnZT0xJnN0b3JlSWQ9NjE3MyZxdWVyeT1zaWV0ZSZzcGVsbGluZz1mYWxzZQ==&uuid=d2bc9a70-5efb-11eb-a179-af3690198cb9&vid=d54095e8-5efb-11eb-9695-0242ac12000e&g=a')

it's not working via Python, but when insert solved key in Chrome console it's works, please help me.
handleCaptcha("resolved")

@kratzky

This comment has been minimized.

Copy link

@kratzky kratzky commented Jan 25, 2021

@arielo82

I executed the code of beggining, but callback is null.

null significa que no hay callback
pon el token en g-recaptcha-response y haz click en el boton Consultar

@arielo82

This comment has been minimized.

Copy link

@arielo82 arielo82 commented Jan 25, 2021

Gracias kratzky!

@dellyet

This comment has been minimized.

Copy link

@dellyet dellyet commented Jan 29, 2021

Hi,

when I run this Script a get an output:

Screenshot

I call this function in my Code:

IJavaScriptExecutor e = driver;
e.ExecuteScript("___grecaptcha_cfg.clients[0].o.o.callback('{" + captcha + "}')");

It ends up with no exception but anyway with no submitting the login.

When i try to fire the command from Browser:

___grecaptcha_cfg.clients[0].o.o.callback('{2CaptchaResponse}')

I get the error "undefined".

After hours of searching, I don't know what to do next. Can someone help me please?

Thanks a lot!

@nhordez

This comment has been minimized.

Copy link

@nhordez nhordez commented Jan 31, 2021

import time

import requests
from selenium import webdriver


API_2CAPTCHA = 'your key'
URL_POST_CAPTCHA = 'http://2captcha.com/in.php'
URL_GET_CAPTCHA = 'http://2captcha.com/res.php'


def resolve_captcha(blocked_url):
    options = webdriver.ChromeOptions()
    user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36'
    options.add_argument('user-agent={0}'.format(user_agent))

    options.add_argument("--disable-blink-features")
    options.add_argument("--disable-blink-features=AutomationControlled")
    driver = webdriver.Chrome(chrome_options=options)
    driver.execute_script("return navigator.userAgent")
    for x in range(10):
        if x == 0:
            driver.get(blocked_url)
            time.sleep(5)

        data_site_key = driver.find_element_by_css_selector('.g-recaptcha').get_attribute('data-sitekey')

        response = requests.get(
            'http://2captcha.com/in.php?key={key}&method=userrecaptcha'
            '&googlekey={data_sitekey}&pageurl={site_url}?appear=1&here=now'.
                format(
                key=API_2CAPTCHA,
                data_sitekey=data_site_key,
                site_url=blocked_url
            )
        )
        timeout = 8
        resolved = False
        for i in range(8):
            time.sleep(timeout)
            timeout += 8

            id_message = response.text.split('|')[-1]
            resolved_captcha = requests.get(
                '{}?key={}&action=get&id={}'.format(
                    URL_GET_CAPTCHA,
                    API_2CAPTCHA,
                    id_message
                )
            )
            resolved_token = resolved_captcha.text.split('|')

            if resolved_token[0] == 'OK':
                resolved = resolved_token[-1]
                print(resolved)
                break

        res = f'handleCaptcha("{resolved}")'
        driver.execute_script(res)

        if driver.current_url != blocked_url:
            break

resolve_captcha('https://www.walmart.com/blocked?url=L2dyb2NlcnkvdjQvYXBpL3Byb2R1Y3RzL3NlYXJjaD9jb3VudD02MCZmaWx0ZXI9Z2hzX2JyYW5kflNpZXRlJTIwRmFtaWx5JTIwRm9vZHMmb2Zmc2V0PTAmcGFnZT0xJnN0b3JlSWQ9NjE3MyZxdWVyeT1zaWV0ZSZzcGVsbGluZz1mYWxzZQ==&uuid=d2bc9a70-5efb-11eb-a179-af3690198cb9&vid=d54095e8-5efb-11eb-9695-0242ac12000e&g=a')

it's not working via Python, but when insert solved key in Chrome console it's works, please help me.
handleCaptcha("resolved")

Have anyone managed to solve the call with the token in the callback function? Having the same issue, from console it is working but from Python it is not?

TIA, appreciate the help.

@chwba

This comment has been minimized.

Copy link

@chwba chwba commented Jan 31, 2021

Christ this is a javascript snippet, would you stop bloating comments with full code snippets of your implementations?.... The topic is the snippet scraping captcha information about a target site and as an addition it would be nice to have it also scrape the "submit" function if there is no callback function.

Any js dev maybe got an idea how to strip out the mechanics from https://antcpt.com/eng/download/mozilla-firefox.html or https://antcpt.com/eng/download/google-chrome-options.html to create a generic solution for the various different captcha submission mechanics, which are hard to figure out for non-js devs? Having a hard time to figure it out for the other various targets (20+)..

^ would be much more interesting, as it would solve the 'submission' mechanics once and for all.

@cybernetor066

This comment has been minimized.

Copy link

@cybernetor066 cybernetor066 commented Feb 4, 2021

Hello Guys Please anyone can help me with this one?, It doesnt have a callback function. Neither does it go through, even when i hit the submit button or try to submit with JavaScript snippet. Here is the website:

https://www.presearch.org/register

After i input the code, it tells me this warning in red: "The g-recaptcha-response field is required."

Please help me. thanks in advance.

@albrechtmate

This comment has been minimized.

Copy link

@albrechtmate albrechtmate commented Feb 4, 2021

import time

import requests
from selenium import webdriver


API_2CAPTCHA = 'your key'
URL_POST_CAPTCHA = 'http://2captcha.com/in.php'
URL_GET_CAPTCHA = 'http://2captcha.com/res.php'


def resolve_captcha(blocked_url):
    options = webdriver.ChromeOptions()
    user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36'
    options.add_argument('user-agent={0}'.format(user_agent))

    options.add_argument("--disable-blink-features")
    options.add_argument("--disable-blink-features=AutomationControlled")
    driver = webdriver.Chrome(chrome_options=options)
    driver.execute_script("return navigator.userAgent")
    for x in range(10):
        if x == 0:
            driver.get(blocked_url)
            time.sleep(5)

        data_site_key = driver.find_element_by_css_selector('.g-recaptcha').get_attribute('data-sitekey')

        response = requests.get(
            'http://2captcha.com/in.php?key={key}&method=userrecaptcha'
            '&googlekey={data_sitekey}&pageurl={site_url}?appear=1&here=now'.
                format(
                key=API_2CAPTCHA,
                data_sitekey=data_site_key,
                site_url=blocked_url
            )
        )
        timeout = 8
        resolved = False
        for i in range(8):
            time.sleep(timeout)
            timeout += 8

            id_message = response.text.split('|')[-1]
            resolved_captcha = requests.get(
                '{}?key={}&action=get&id={}'.format(
                    URL_GET_CAPTCHA,
                    API_2CAPTCHA,
                    id_message
                )
            )
            resolved_token = resolved_captcha.text.split('|')

            if resolved_token[0] == 'OK':
                resolved = resolved_token[-1]
                print(resolved)
                break

        res = f'handleCaptcha("{resolved}")'
        driver.execute_script(res)

        if driver.current_url != blocked_url:
            break

resolve_captcha('https://www.walmart.com/blocked?url=L2dyb2NlcnkvdjQvYXBpL3Byb2R1Y3RzL3NlYXJjaD9jb3VudD02MCZmaWx0ZXI9Z2hzX2JyYW5kflNpZXRlJTIwRmFtaWx5JTIwRm9vZHMmb2Zmc2V0PTAmcGFnZT0xJnN0b3JlSWQ9NjE3MyZxdWVyeT1zaWV0ZSZzcGVsbGluZz1mYWxzZQ==&uuid=d2bc9a70-5efb-11eb-a179-af3690198cb9&vid=d54095e8-5efb-11eb-9695-0242ac12000e&g=a')

it's not working via Python, but when insert solved key in Chrome console it's works, please help me.
handleCaptcha("resolved")

Have anyone managed to solve the call with the token in the callback function? Having the same issue, from console it is working but from Python it is not?

TIA, appreciate the help.

Hi, I'm facing with the same problem. Did you find a solution for that? I'm using selenium with python, and i cant call the callback function.

@Oleh-Hrebchuk

This comment has been minimized.

Copy link

@Oleh-Hrebchuk Oleh-Hrebchuk commented Feb 4, 2021

@meenapriya-ui

This comment has been minimized.

Copy link

@meenapriya-ui meenapriya-ui commented Feb 26, 2021

Hi,

I'm able to retrieve / scrape the URL using the method GET and while trying to POST the request with the payload, It is saying success but form did not get submitted, I'm bit confused to call the callback function in python,form is submitted via callback function,can you please give some suggestion to call the callback function in python?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment