I need to log in to the website using C #. The authorization form contains reCAPTCHA. It is necessary to process it somehow (i.e., pull out the pictures, the text of the assignment and allow the user to 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 something like this page 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 pictures with reCAPTCHA? The old reCAPTCHA seemed to be a single image that could be downloaded at the following address: http://www.google.com/recaptcha/api/image?c=[challenge from RecaptchaState] . What to do with the new, I do not know. Not really versed in 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 to be passed by the user. Something like WebBrowser, but not the whole page, but only the captcha itself, obtained from WebResponse.

  • We need to look at recaptcha.js , it still draws a picture, see how and from what, then repeat :) a lot of recaptcha services, as a piece of advice, look for a php implementation for this type of captcha, it probably is in nature, and you will not make php labor to understand what and how and repeat on C #. - NewView
  • one
    Here and here and here I hope it will help you too :) well, and the final part - NewView
  • Is it possible to simply display this to the user? Element from the page code. Something like WebBrowser, only with support for js. Interaction with the site is carried out through WebRequest / WebRespose - D .Stark
  • The last link is a working example in C # , download it :) and try. - NewView
  • Good. Do not help with this question: ru.stackoverflow.com/questions/845766/… - D .Stark

1 answer 1

I open the site in WebBrowser, get all the pictures from the site and so find the captcha picture itself:

 private void openAndWaitCompliteURL(string url) { webBrowser.Navigate(url); while (webBrowser.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); } } 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; } } openAndWaitCompliteURL(url); capchaForm.capchaPictureBox.ImageLocation = getImageWhenLoad("src"); 

Then I display the picture in the PictureBox.

  • I do not use WebBrowser, because the site I need it loads incorrectly. And in general, JS support is bad. We need a solution on CefSharp. You could only help if you offered a script that will hide all the elements of the visual tree except <div class="g-recaptcha" .. - D .Stark
  • @ D.Stark But in the question there is nothing about CefSharp and the hiding of the visual tree ... And why bother with the hiding of individual elements, it's easier to hide the entire browser and show the picture separately (if there really is a picture). - MSDN.WhiteKnight
  • @ MSDN.WhiteKnight Read the comments to the question. The picture may not be one, while the images can be loaded as they are resolved. And, what if I do not correctly decide? - D .Stark
  • @ MSDN.WhiteKnight "But there is nothing about CefSharp and the concealment of the visual tree in the question" - there are comments in the comments - D .Stark
  • Ask a separate question about the elements of the visual tree - sanmai