Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2004-10-12
9
870 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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
 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…

808 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