-
August 22nd, 2004, 12:43 AM
#1
Pulling HTML off the WebBrowser
I faught with this for a year just to find the answer. Noone here seemed to be able to answer it. I've seen it posted many times. Each time the question is answered with a method that works for some aplications but not for others. So I taught myself c++ and windows programming just so I could understand how the control actually works. Well now I've got a simple technique that works every time.
WebBrowser1.Document.All.Item.innerHTML
Will get you the HTML off a simple webpage.
If you have frames it's a little more complicated. That line of code will give you all the HTML not included in the frame. Now here's the part that makes you want to smack yourself in the head. If you use that line of code on a website with frames say MSDN library you'll get the HTML that creates the frame. Inside that little chunck of html you will find the rest of the information you need that is the name of the fame. it'll look something like this.
<FRAME border=0 name=fraRightFrame
if you take that frame name and plug it in to this line of code you will get the html for that particular frame.
WebBrowser1.Document.frames("fraRightFrame").Document.All.Item.innerHTML
You can also pull just one item out of the HTML text by placing an index number after the Item. You can get a count of the number of items by simply placing .length at the end instead of InnerHTML. Or you could just get the text by using InnerText instead of InnerHTML.
I hope this helps at least a few people who are trying to learn how to program.
-
April 22nd, 2006, 07:41 AM
#2
Re: Pulling HTML off the WebBrowser
I have one main web page having the following java script
function JobClass(date, time, id, action)
{ this.date = date; this.time = time; this.id = id; this.action= action;
}
var myjobs=new Array();
myjobs[0]=new JobClass('20060101','13000','123456','on');
myjobs[1]=new JobClass('20060102','14000','123457','off');
myjobs[2]=new JobClass('20060103','15000','123458','on');
function triggerAddJob(){ }
I have created one command object in the web page.
MY PROBLEM
I want to add a parameter to the command object that will accept the value ( myjobs[0] ) from the main page.
WE NEED AN URGENT REPLY ON THIS.
IF YOU CAN HELP OUT CAN YOU SEND A REPLY TO MY E-MAIL AT : surajsv@yahoo.com
THANK YOU
-
January 24th, 2008, 04:12 PM
#3
Re: Pulling HTML off the WebBrowser
I have a desktop C# application with a WebBrowser control. This control loads a https page containing a few frames. I'm trying to access the form elements in one of the frames using similar code to this one:
WebBrowser1.Document.Frames("fraRightFrame").Document.All.Item.innerHTML
; however, I am getting some Security exception being thrown. I googled about this and seems the explanation is to have frames pointing to different domains (servers). But is my case everything comes from one domain.
I wonder is anybody experienced this kind of problems and what is the workaround. I'm using Visual Studion 2005 that runs on Windows Vista.
Alexi
-
January 24th, 2008, 04:16 PM
#4
Re: Pulling HTML off the WebBrowser
Well, you dug up an old question for the wrong language then. Try VB.Net or C#
-
January 24th, 2008, 04:34 PM
#5
Re: Pulling HTML off the WebBrowser
I thought C# is the right direction ... Are you saying I should use VB.Net? Anyhow, I would appreciate if somebody gives me directions what is wrong.
The WebBrowser control might not be the best solution for setting/getting the values of HTML elements in frame's form and for simultation of clicking buttons. If this is the case, I am opened to other alternatives.
Thanks, Alexi
-
January 24th, 2008, 04:43 PM
#6
Re: Pulling HTML off the WebBrowser
I wasn't sure what language you were using. You didn't post any code.
I also meant that you should start your own thread, rather than finding an unresolved one.
-
January 24th, 2008, 05:16 PM
#7
Re: Pulling HTML off the WebBrowser
You are right!
I haven't paid attention that this is the VB 6.0 forum. Actually, the thread was result of searching and was very similar to my case & code. This is the reason for posting it there and I want to apologize if this caused a confusion/problem.
-
February 23rd, 2010, 12:11 PM
#8
Re: Pulling HTML off the WebBrowser
The solution: WebBrowser1.Document.All.Item.innerHTML
doesn't work on my system. (I think Document.All became obsolete with IE4)
After delving a bit further I found the following solution worked:
htmltext = WebBrowser1.Document.body.innerHTML
or
htmltext = WebBrowser1.Document.getelementById("insert html id string here").innerHTML
(Note: Above solution will only work on IE5 or greater)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|