c# – Get image from reCAPTCHA


I need to log in to a website using C #. The reCAPTCHA is present in the authorization form. It is necessary to somehow process it (that is, pull out the pictures, the text of the task and let the user solve this matter).

For starters, I see an empty div class="g-recaptcha" data-sitekey="..." . From here you can take the value of the data-sitekey . Let's follow the link https://www.google.com/recaptcha/api/challenge?k=[data-sitekey value] and a page like this will load:

var RecaptchaState = {
    challenge : '...',
    server : 'https://www.google.com/recaptcha/api/',
    site : '...',

document.write('<scr'+'ipt type="text/javascript" s'+'rc="' + RecaptchaState.server + 'js/recaptcha.js"></scr'+'ipt>');

How can I pull images from reCAPTCHA? The old reCAPTCHA was apparently a single image that could be downloaded from this address: http://www.google.com/recaptcha/api/image?c=[challenge from RecaptchaState] . I don’t know what to do with the new one. I don't know much about web programming.

UPD: Perhaps there is another solution in which we do not need to receive a picture. It may be possible to somehow display the captcha for the user to go through. Something like WebBrowser, just not the entire page, but only the captcha itself, obtained from WebResponse.


I open the site in WebBrowser, get all the images from the site, and this is how I find the captcha image itself:

private void openAndWaitCompliteURL(string url) {
            while (webBrowser.ReadyState != WebBrowserReadyState.Complete) {
private string getImageWhenLoad(string attr) {
        HtmlDocument doc = webBrowser.Document;
        HtmlElementCollection htmlElementCollection = doc.Images;
        foreach (HtmlElement htmlElement in htmlElementCollection) {
            string imgUrl = htmlElement.GetAttribute(attr);
            return imgUrl;
capchaForm.capchaPictureBox.ImageLocation = getImageWhenLoad("src");

Then I display the picture in the PictureBox.

Scroll to Top