leontager Posted January 4, 2004 Posted January 4, 2004 Hi, I use the following code to navigate to a certain website obIE(i) = New SHDocVw.InternetExplorer() obIE(i).Navigate(address) obIE(i).Visible = True Now I want to read the text from the page. I know about innertext which works fine unless there is a frame on the page. How can I read the text from a certain frame? Quote
leontager Posted January 5, 2004 Author Posted January 5, 2004 actually source would be fine too. I need to detect any any change in that frame. Quote
Leaders dynamic_sysop Posted January 5, 2004 Leaders Posted January 5, 2004 the best i could come up with after a bit of messing is this, hope it helps... If Not doc Is Nothing Then Dim x As Integer = 0 Dim frm As mshtml.HTMLWindow2Class For x = 0 To doc.frames.length - 1 frm = DirectCast(doc.frames.item(x), mshtml.HTMLWindow2Class) MessageBox.Show(frm.document.activeElement.innerText) Next End If Quote
leontager Posted January 9, 2004 Author Posted January 9, 2004 Your best will do :-) Thank you very much. Quote
jimmknopf Posted January 21, 2004 Posted January 21, 2004 (edited) Hallo, I use also the SHDocVw.InternetExplorer() in my ASP.NET (C#) applikation, and want to get the mshtml.FramesCollection, but I get every time an exception. The value of the InternetExplorer.Document.frames is: <error: an exception of type: {System.InvalidCastException} occurred> Abstract: //constructor InternetExplorerClass mIE = new InternetExplorerClass(); mIE.Visible = true; //... mIE.Navigate2(ref objURL, ref a, ref a, ref a, ref a); // DocumentComplete if(URL.ToString().Equals(url)) { Console.WriteLine(mIE.Document.ToString()); mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2) mIE.Document; Console.WriteLine(doc.frames.length); } [code=csharp] This are the tag�s of my Frameset: [code] <frameset cols="*,*"> <frame name="left" src="WebForm1.aspx"> <frame name="right" src="WebForm2.aspx"> </frameset> [code] I don't know why I get the error? Edited January 21, 2004 by jimmknopf Quote
rede Posted October 19, 2005 Posted October 19, 2005 (edited) Access the the InternetExplorer.Document at the right time and from the right thread Hi, After spending the whole day on it I have found a solution. http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?FeedbackId=25ab57f0-4d1c-45d4-ac7f-be8061a2ec58#Workarounds You have to read InternetExplorer.Document from the main thread. Please note the use of STAThread. Read more about it here: http://blogs.msdn.com/jfoscoding/archive/2005/04/07/406341.aspx In the example below I know that there are three frames and I want to be sure that they are all loaded before I access them (This is another problem you have to avoid...) /Patrick using System; namespace ConsoleApplication7 { /// <summary> /// Summary description for Class1. /// </summary> using System; using mshtml; using SHDocVw; using System.Collections; using System.Threading; namespace ConsoleApplication1 { class Class1 { static InternetExplorer ie = null; [sTAThread] static void Main(string[] args) { Class1 class1 = new Class1(); class1.Test(); Console.Read(); } AutoResetEvent firstDocumentCompleted; AutoResetEvent lastDocumentCompleted; int completedDocuments; int expectedDocuments; public void Test() { Console.WriteLine("Starting:" + Thread.CurrentThread.ApartmentState.ToString()); ie = new SHDocVw.InternetExplorer(); ie.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(DocumentComplete); ie.Visible = true; firstDocumentCompleted = new AutoResetEvent(false); lastDocumentCompleted = new AutoResetEvent(false); completedDocuments = 0; expectedDocuments = 4; object o = null; ie.Navigate("http://www.htmq.com/html/sample/frame.htm", ref o, ref o, ref o, ref o); firstDocumentCompleted.WaitOne(30000, false); IHTMLDocument2 document = (IHTMLDocument2)ie.Document; lastDocumentCompleted.WaitOne(30000, false); IHTMLFramesCollection2 frames = (IHTMLFramesCollection2)document.frames; for (int index = 0; index < frames.length; index++) { object i = index; frames.item(ref i); IHTMLWindow2 window = (IHTMLWindow2)frames.item(ref i); IHTMLDocument2 frameDocument = (IHTMLDocument2)window.document; Console.WriteLine(frameDocument.body.innerHTML); } Console.WriteLine(); } public void DocumentComplete(object pDisp, ref object URL) { Console.WriteLine("DocumentComplete:" + Thread.CurrentThread.ApartmentState.ToString()); int i = Interlocked.Increment(ref completedDocuments); if (i == 1) { firstDocumentCompleted.Set(); } if (i == expectedDocuments) { lastDocumentCompleted.Set(); } } } } } Edited October 20, 2005 by rede Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.