Pulling HTML off the WebBrowser
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Pulling HTML off the WebBrowser

  1. #1
    Join Date
    Jan 2002
    Posts
    195

    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.

  2. #2
    Join Date
    Apr 2006
    Posts
    1

    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

  3. #3
    Join Date
    Jan 2003
    Location
    Bulgaria
    Posts
    56

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,961

    Re: Pulling HTML off the WebBrowser

    Well, you dug up an old question for the wrong language then. Try VB.Net or C#
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jan 2003
    Location
    Bulgaria
    Posts
    56

    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

  6. #6
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,961

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

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Jan 2003
    Location
    Bulgaria
    Posts
    56

    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.

  8. #8
    Join Date
    Feb 2010
    Posts
    1

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center