Hi All,
I am writting a C# project in which am using Browser Control. The object of this project to read values of JavaScript's variables values on the current page ,and add those values to ListBox control. Can anybody show me how to do this. Please help if you can I need to do this ASAP for my job.
Thanks,
Asif
Saul LeightonPosted May 17, 2010, 12:50 PM
Did you ever figure out how to do this? I need to do exactly the same thing.
I'm trying to scrape a dynamic web page using WebBrowser.Document, then casting this to IHTMLDocument3 like this:
IHTMLDocument3 HtmlDoc3 = (IHTMLDocument3)this.webBrowser.Document;
from here, we can do:
foreach (IHTMLElement element in HtmlDoc3.getElementsByTagName("div"))
{...}
No problem.
However, when we try to get the scripts, we only see Javascript for those scripts that are directly entered into the page, NOT ones that are loaded from separate .js files :-(
IHTMLDocument2 HtmlDoc2 = (IHTMLDocument2)this.webBrowser.Document;
IHTMLElementCollection scripts2 = HtmlDoc2.scripts;
foreach (IHTMLScriptElement script in scripts2)
{
MessageBox.Show("src = " + script.src + "\ntext = " + script.text + "\ntype = " + script.type);
}
For this apparently, we have to get the cached javascript, using "wininet.dll":
See this article: http://www.codeproject.com/KB/cs/WebCacheTool.aspx
OK, so let's assume we can get this, it STILL does not give us access to the actual variables at run-time.
How do we get those? I weas thinking of maybe attaching an event handler in my C# code that gets fired whenever Java script changes any value on the HTML page, but no luck yet.
Anyone out there done this before? Any ideas or help much appreciated. :-)
Cheers, Saul