Solved

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

Posted on 2004-10-12
9
877 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
[X]
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
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

626 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