Solved

How to use axWebBrowserto get the HTML source of the page in a frameset?

Posted on 2004-10-12
9
855 Views
Last Modified: 2007-12-19
Hello,

A multi-frame page contains 3 html pages: page A, page B and page C. I need to get the HTML source of page C. I tried to use AxSHDocVw.AxWebBrowser to do that:

mshtml.HTMLDocument htm = (mshtml.HTMLDocument)axWebBrowser1.Document;

I can get the frame count by "htm.frames.length".

But, while I tried to use "htm.frames(2).Document.documentElement.innerText" to get HTML source, it said "Cannot apply indexing with [] to an expression of type 'mshtml.FramesCollection'".

Can you help me to resolve it? I have spent many days on it.

Thanks,
Simon
0
Comment
Question by:cjchuang98
9 Comments
 
LVL 18

Expert Comment

by:armoghan
ID: 12295470
see this link may help, it is in C but can help you

http://www.kbalertz.com/kb_815727.aspx

I think you have to do something like
htm.frames.items(2).Document.documentElement.innerText

that is what seems to be from the C code
0
 

Author Comment

by:cjchuang98
ID: 12296136
I have tried "htm.frames.item(2).Document.documentElement.innerText;". But it said "The best overloaded method match for 'mshtml.IHTMLFramesCollection2.item(ref object)' has some invalid arguments".

Do you know any sample in C#.NET?

0
 
LVL 8

Expert Comment

by:tomvergote
ID: 12296198
"m.frames(2).Docu"

if you are using c#.NET collections are indicated using []
so if you are trying to reach the 3nd frame you would use .frames[2]

what you are trying is a method call?
0
 

Author Comment

by:cjchuang98
ID: 12296279
I have tried "htm.frames[2].Document.documentElement.innerText;". But it said "Cannot apply indexing with [] to an expression of type 'mshtml.FramesCollection'".

Any other method?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 18

Expert Comment

by:armoghan
ID: 12296403
try creating an Empty Object and send its reference
Object o = new Object ();
htm.frames.item(o).Document.documentElement.innerText

or if you some how can get all the items list
I could not get what __Box was in the article
0
 
LVL 18

Accepted Solution

by:
armoghan earned 250 total points
ID: 12297159
ok it took me some effort but I found it out



see this code i is increamented



                              HTMLDocument myDoc = new HTMLDocumentClass();
                              myDoc = (HTMLDocument) axWebBrowser1.Document;
                              FramesCollection c = myDoc.frames;
                              
                              Object o = i;
                              i++;
                              Object c1 =null;
                              
                              try
                              {
                                    c1 =  c.item(ref o);
                              }
                              catch(Exception ex)
                              {
                                    Console.WriteLine(ex.Message);
                              }
                              HTMLWindow2Class c2 = ((HTMLWindow2Class)c1);
                              
                              Console.WriteLine(((mshtml.IHTMLElement)(((mshtml.HTMLDocumentClass)(((mshtml.IHTMLDocument2)((c2.document))))).documentElement)).innerText);
0
 

Author Comment

by:cjchuang98
ID: 12304804
Hi armoghan,

Thanks for your help. Your code works.

The following are my code based on yours:
-------------------------------------------------------------------------------------------------
mshtml.HTMLDocument htm = (mshtml.HTMLDocument)axWebBrowser1.Document;
for (int m = 0; m < htm.frames.length; m++)
{
      Object myObj = m;
      mshtml.HTMLWindow2Class myPage1 = (mshtml.HTMLWindow2Class)htm.frames.item(ref myObj);
      mshtml.IHTMLDocument2 myPage2 = (mshtml.IHTMLDocument2)myPage1.document;
      mshtml.HTMLDocumentClass myPage3 = (mshtml.HTMLDocumentClass)myPage2;
      mshtml.IHTMLElement myPage4 = (mshtml.IHTMLElement)myPage3.documentElement;

      Console.WriteLine(myPage4.innerHTML);
}
-------------------------------------------------------------------------------------------------

But, are there any possible to reduce the conversion?
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12315692
Yes sure there would be. I have not checked
I used quick watch to find out the solution. which starts type casting unnecessarly..
There may be some properties which will be accessible without Type casting.
0
 
LVL 8

Expert Comment

by:bman9111
ID: 14032465
armoghan,

not sure if u are still around but how would this code be in vb.net:

ok it took me some effort but I found it out



see this code i is increamented



                         HTMLDocument myDoc = new HTMLDocumentClass();
                         myDoc = (HTMLDocument) axWebBrowser1.Document;
                         FramesCollection c = myDoc.frames;
                         
                         Object o = i;
                         i++;
                         Object c1 =null;
                         
                         try
                         {
                              c1 =  c.item(ref o);
                         }
                         catch(Exception ex)
                         {
                              Console.WriteLine(ex.Message);
                         }
                         HTMLWindow2Class c2 = ((HTMLWindow2Class)c1);
                         
                         Console.WriteLine(((mshtml.IHTMLElement)(((mshtml.HTMLDocumentClass)(((mshtml.IHTMLDocument2)((c2.document))))).documentElement)).innerText);
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now