Answer the question
In order to leave comments, you need to log in
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;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question