L
L
largotek2014-09-10 23:36:24
.NET
largotek, 2014-09-10 23:36:24

Why webbrowser does not work correctly?

Good evening experts.
There is a task, authorization and collection of information from the site.
The first problem was in authorization, as there is a dynamic captcha. You can't just download by url because the captcha is dynamic (sorry for the pun) and each time the picture is different. The solution is to use the webBrowser and pull out the image from there. The solution helped here www.cyberforum.ru/visual-basic/thread903024.html#p...

string uri = "http://joblab.ru/access.php/";
            
            result = new string[] { "", "" };

            webBrowser1.Navigate(uri);
            webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
            while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
            {
                Application.DoEvents();
            }

            IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.DomDocument;
            IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();

            foreach (IHTMLImgElement img in doc.images)
            {
                imgRange.add((IHTMLControlElement)img);

                imgRange.execCommand("Copy", false, null);

                using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
                {
                    if (img.nameProp.Contains("PHPSESSID"))
                    {
                        Image imgCpt = bmp;
                        string captch = CaptchaWindow.Show(imgCpt);
                        string cookValue = img.nameProp.Replace("index.php?PHPSESSID=", "");
                        result = new string[2];
                        result[0] = captch;
                        result[1] = cookValue;
                        cook = cookValue;
                    }
                }
            }

            webBrowser1.Document.GetElementById("auth_name_job").SetAttribute("value", login);
            webBrowser1.Document.GetElementById("pass").SetAttribute("value", pass);
            webBrowser1.Document.GetElementById("keystring").SetAttribute("value", result[0]);

            foreach (HtmlElement he in webBrowser1.Document.GetElementsByTagName("input"))
            {
                if (he.GetAttribute("value").Equals("employer"))
                {
                    he.InvokeMember("click");
                    break;
                }
            }

            foreach (HtmlElement he in webBrowser1.Document.GetElementsByTagName("input"))
            {
                if (he.GetAttribute("value").Equals("Войти"))
                {
                    he.InvokeMember("click");
                    break;
                }
            }

Further, everything is going normally, but after a certain number of requests, a page appears where you need to enter the captcha. And it seems that you need to do the same as before, but an error occurs.
We do exactly the same, but in Navigate we insert a different url. And that's it, he doesn't want to work. Why is this happening? I understand that I don’t have enough knowledge of the platform, and I don’t know how to correctly use these elements, so I ask the guru for help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question