+ Reply to Thread
Results 1 to 3 of 3

Thread: web browser control: How to programatically access html code

  1. #1
    skydiver is offline VB.NET Forum Newbie skydiver is on a distinguished programming path ahead
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    Jun 2006
    Posts
    3
    Reputation
    0

    Question web browser control: How to programatically access html code

    I'm using vb.net and the web browser control on a win form application where I have a dynamically created 'parent' html page that contains an 'iframe' that points to another dynamically created html page. Get it? Now, the exact reason why I'm doing this isn't the issue, but I'm trying to access the actual html code that resides within the child (iframe) page programatically through vb.net and the web browser control properties/methods (or whatever else...).

    Here's what's going on with the code below:
    The parent page gets 'navigated' to within the browser control that's sitting on my win form. The iframe gets loaded as well, and immediately begins the submission of the form data (currently 12 times, with an interval of 250ms). As each submission occurs, the parent gets updated through javascript with the current iteration number. When complete, the response to the form posting will present info within the iframe element. I need the actual HTML of the iframe element at this time but I'm not sure how to reference the child objects (elements?) within the web browser control. Can you help? Please include some examples if you're able. Thanks for the help!

    Here's the Parent page:
    Code:
    <HTML>
    <BODY>
    <form id="formsubmit">
    <input type="text" id="postCounter" value="0";>
    <iframe name="iFrame1" src="childpage.html" width="50%" align="left">
    </form>
    </iframe>
    </BODY>
    </HTML>
    Here's the Child code:
    Code:
    <HTML>
    <head>
    <SCRIPT type="text/javascript">
    	var t=0;
    	var i=0;
    function load()
    {
    	t = setInterval("submitme()",250);
    }
    
    function submitme()
    {
    	var ctl;
    	ctl=parent.document.forms[0].postCounter;
    	i = parseInt(ctl.value);
    	i=i+1;
    	ctl.value = i;
    	if (parseInt(i)<12)
    	{
    	  document.forms[0].submit();
    	}
    	else
    	{
    	  clearInterval(t);
    	}
    }
    </SCRIPT>
    </head>
    <body onLoad="load();">
    <form>  FORM TO POST GOES HERE</form>
    </BODY>
    </HTML>
    ---------------------------------------------
    So you say I jump from perfectly good airplanes? Maybe you should take a gander and the junk we jump from...
    Probably safer outta the plane than in.

  2. #2
    demausdauth is offline VB.NET Forum Master demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame demausdauth puts e.f. hutton to shame
    .NET Framework
    .NET 2.0 (VS 2005)
    Join Date
    Mar 2008
    Location
    Minnesota
    Posts
    268
    Reputation
    220

    Default

    not sure if this will help you or not but kleinama in VBForums has a pretty good Webpage manipulation thread going:

    Manipulate/Change/Form Fill data in webpages using the Webbrowser control - VBForums

  3. #3
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute JohnH has a reputation beyond repute
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Age
    37
    Posts
    10,843
    Reputation
    1443

    Default

    To access the Html elements that the browser parses into the DOM tree you always use the Document property, this is your door in. In this case you must take a step back in the tree from the loaded document back to the Window object to access its Frames, then you select the correct frame by integer/string index and get into its Document tree. Here is a sample path that uses what I just described and display the body source of a frame:
    Code:
    MsgBox(Me.WebBrowser1.Document.Window.Frames(0).Document.Body.InnerHtml)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

     

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts