How to Get data in WebBrowser

Mar 17 2011 12:27 PM
Windows Form has WebBrowser Control, button "Login" and button "Get data" (Windows Control). When i click button Login: login website A (I passed). When i logined, WebBrowser return 3 frame (top frame, left frame and center frame).  Center frame shows all product (product name, product price, ...). After 1 minute, this frame refresh. This frame has:  <iframe name="Data" src="" style="display: none"></iframe> <form action="GetPrice.aspx" target="Data" name="GetPrice" style="display: none"> <input type="hidden" name="hidPID" value="123" /> <input type="hidden" name="hidC" value="5" /> </form> The follow result in browser:  <script language="javascript"> var NameP = "Product 123"; var CodeP = "123"; var UnitP = "123,456"; </script> How to get this result when i click button "Get data"?

I use code:

HtmlDocument objHTMLDoc = webBrowserIbet.Document;

string strUrl = webBrowserIbet.Url.ToString();  // www.abc.com/main.aspx

strUrl = strUrl.Replace("main.aspx", "GetPrice.aspx?hidPID=123&hidC=5");

string strContent = "";

HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(strUrl);

myRequest.Method = "GET";

myRequest.ContentType = "text/html; charset=utf-8";

myRequest.Referer = webBrowserIbet.Url.ToString();

myRequest.CookieContainer = new CookieContainer();

Uri uri = new Uri(strUrl);

myRequest.CookieContainer.SetCookies(uri, webBrowserIbet.Document.Cookie);

HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();

using (StreamReader sr = new StreamReader(myResponse.GetResponseStream()))

{

strContent = sr.ReadToEnd();

sr.Close();

}

myResponse.Close();


But result is empty not 

<script language="javascript"> var NameP = "Product 123"; var CodeP = "123"; var UnitP = "123,456"; </script>

Help me!!!!!!

Answers (1)