WebBrowser1.DocumentText

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nime

    WebBrowser1.DocumentText

    How can I grab html source of a frame?

    I can retrive main frame by WebBrowser1.Doc umentText
    but I want to retrive inner (child) frame...

    WebBrowser1.Doc ument.Window.Fr ames(0).Documen tText like thing doesn't exist...





  • Cor Ligthert [MVP]

    #2
    Re: WebBrowser1.Doc umentText

    Nime,

    You are number three asking this in this newsgroup. In my idea you cannot do
    that with the new webbrowser (it is missing downloadcomplet e). You can do it
    with the Axwebbrowser. If you only want to get one special frame with its
    own URL, than you can as well use this



    I hope this helps,

    Cor




    "nime" <ea2005@planev. comschreef in bericht
    news:eUqN4SWnGH A.1584@TK2MSFTN GP02.phx.gbl...
    How can I grab html source of a frame?
    >
    I can retrive main frame by WebBrowser1.Doc umentText
    but I want to retrive inner (child) frame...
    >
    WebBrowser1.Doc ument.Window.Fr ames(0).Documen tText like thing doesn't
    exist...
    >
    >
    >
    >
    >

    Comment

    • gene kelley

      #3
      Re: WebBrowser1.Doc umentText

      On Sun, 2 Jul 2006 02:18:48 +0300, "nime" <ea2005@planev. comwrote:
      >How can I grab html source of a frame?
      >
      >I can retrive main frame by WebBrowser1.Doc umentText
      >but I want to retrive inner (child) frame...
      >
      >WebBrowser1.Do cument.Window.F rames(0).Docume ntText like thing doesn't exist...
      >
      >
      >
      >
      See if this helps:

      Private LinksTable As Hashtable

      Private Sub WebBrowser1_Doc umentCompleted( ByVal _
      sender As Object, ByVal e As _
      System.Windows. Forms.WebBrowse rDocumentComple tedEventArgs) _
      Handles WebBrowser1.Doc umentCompleted

      GetLinksFromFra mes()

      End Sub

      Private Sub GetLinksFromFra mes()
      LinksTable = New Hashtable()
      Dim FrameUrl As String

      If (Not WebBrowser1.Doc ument Is Nothing) Then
      With WebBrowser1.Doc ument
      Dim CurrentWindow As HtmlWindow = .Window
      If (CurrentWindow. Frames.Count 0) Then
      For Each Frame As HtmlWindow In _
      Frame.Document. Links
      FrameUrl = Frame.Url.ToStr ing()

      Dim ThisFrameName As String = Frame.Name
      Dim ThisFrameDocume nt As _
      HtmlDocument = Frame.Document

      Dim FrameLinksHash As New Hashtable()
      LinksTable.Add( FrameUrl, FrameLinksHash)

      For Each HrefElement As HtmlElement In _
      Frame.Document. Links
      FrameLinksHash. Add(HrefElement .GetAttribute _
      ("HREF"), "Url")
      Next
      Next
      Else
      Dim DocLinksHash As New Hashtable()
      LinksTable.Add( .Url.ToString() , DocLinksHash)

      For Each HrefElement As HtmlElement In .Links
      DocLinksHash.Ad d(HrefElement.G etAttribute _
      ("HREF"), "Url")
      Next
      End If
      End With
      End If
      End Sub


      Gene

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: WebBrowser1.Doc umentText

        "nime" <ea2005@planev. comschrieb:
        How can I grab html source of a frame?
        >
        I can retrive main frame by WebBrowser1.Doc umentText
        but I want to retrive inner (child) frame...
        >
        WebBrowser1.Doc ument.Window.Fr ames(0).Documen tText like thing doesn't
        exist...
        \\\
        For Each Frame As HtmlWindow In Me.WebBrowser1. Document.Window .Frames
        MsgBox(Frame.Do cument.All(1).O uterHtml)
        Next Frame
        ///

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://classicvb.org/petition/>

        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: WebBrowser1.Doc umentText

          "Cor Ligthert [MVP]" <notmyfirstname @planet.nlschri eb:
          You are number three asking this in this newsgroup. In my idea you cannot
          do that with the new webbrowser (it is missing downloadcomplet e).
          What about this solution?

          \\\
          Private Sub WebBrowser1_Doc umentCompleted( _
          ByVal sender As Object, _
          ByVal e As WebBrowserDocum entCompletedEve ntArgs _
          ) Handles WebBrowser1.Doc umentCompleted
          If Me.WebBrowser1. ReadyState = WebBrowserReady State.Complete Then
          MsgBox("Documen t and frames loaded!")
          End If
          End Sub
          ///

          --
          M S Herfried K. Wagner
          M V P <URL:http://dotnet.mvps.org/>
          V B <URL:http://classicvb.org/petition/>

          Comment

          • nime

            #6
            Re: WebBrowser1.Doc umentText

            Thank you for your valuable responses.

            I am currently using WebBrowser control to automate a few things like auto-login a site, etc.


            I don't know what is the difference between Navigated and DocumentComplet e events, plus
            in my application, DocumentComplet e event never fired yet... Then I used Navigated instead.
            But the problem is that the document is incomplete. I've examined Document.body.i nnerHTML
            and only a part of the source appears...

            Private Sub WebBrowser1_Nav igated(...)

            Select Case e.Url.ToString

            Case "http://www.domain.com/"

            ''''ProcessMain Page() ' Do nothing

            Case "http://www.domain.com/login.asp" 'Login frame

            ProcessLoginPag e()

            End Select

            End Sub

            Private Sub ProcessLoginPag e()

            Dim frm as HTMLDocument
            Dim el as HTMLElement

            For i = 0 To WebBrowser1.Doc ument.Window.Fr ames.Count - 1

            'Find the login frame
            If WebBrowser1.Doc ument.Window.Fr ames(i).Documen t.Window.Url.To String = "http://www.domain.com/login.asp" Then
            frm = WebBrowser1.Doc ument.Window.Fr ames(i).Documen t

            'Fill the form
            For Each el In frm.Forms
            Select Case el.Name
            Case "login"
            el.InnerText = "username"
            Case "pass"
            el.InnerText = "secret"
            End Select
            Next el



            End If

            Next i

            End Sub


            Comment

            • nime

              #7
              Re: WebBrowser1.Doc umentText

              This event never fired here : (

              "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atwrot e in message news:%23cSGVRdn GHA.2148@TK2MSF TNGP03.phx.gbl. ..
              "Cor Ligthert [MVP]" <notmyfirstname @planet.nlschri eb:
              >You are number three asking this in this newsgroup. In my idea you cannot do that with the new webbrowser (it is missing
              >downloadcomple te).
              >
              What about this solution?
              >
              \\\
              Private Sub WebBrowser1_Doc umentCompleted( _
              ByVal sender As Object, _
              ByVal e As WebBrowserDocum entCompletedEve ntArgs _
              ) Handles WebBrowser1.Doc umentCompleted
              If Me.WebBrowser1. ReadyState = WebBrowserReady State.Complete Then
              MsgBox("Documen t and frames loaded!")
              End If
              End Sub
              ///
              >
              --
              M S Herfried K. Wagner
              M V P <URL:http://dotnet.mvps.org/>
              V B <URL:http://classicvb.org/petition/>

              Comment

              • Cor Ligthert [MVP]

                #8
                Re: WebBrowser1.Doc umentText

                Herfried,

                Did you try it, if it works than it is a great one?

                :-)

                Cor

                "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atschr eef in bericht
                news:%23cSGVRdn GHA.2148@TK2MSF TNGP03.phx.gbl. ..
                "Cor Ligthert [MVP]" <notmyfirstname @planet.nlschri eb:
                >You are number three asking this in this newsgroup. In my idea you cannot
                >do that with the new webbrowser (it is missing downloadcomplet e).
                >
                What about this solution?
                >
                \\\
                Private Sub WebBrowser1_Doc umentCompleted( _
                ByVal sender As Object, _
                ByVal e As WebBrowserDocum entCompletedEve ntArgs _
                ) Handles WebBrowser1.Doc umentCompleted
                If Me.WebBrowser1. ReadyState = WebBrowserReady State.Complete Then
                MsgBox("Documen t and frames loaded!")
                End If
                End Sub
                ///
                >
                --
                M S Herfried K. Wagner
                M V P <URL:http://dotnet.mvps.org/>
                V B <URL:http://classicvb.org/petition/>

                Comment

                • Herfried K. Wagner [MVP]

                  #9
                  Re: WebBrowser1.Doc umentText

                  "Cor Ligthert [MVP]" <notmyfirstname @planet.nlschri eb:
                  Did you try it, if it works than it is a great one?
                  Yes, it worked for the framesets I tested on the Web, but I am not sure if
                  it will still work if one of the frames contains a media stream or similar
                  that is still loading after the actual /documents/ have been loaded.

                  --
                  M S Herfried K. Wagner
                  M V P <URL:http://dotnet.mvps.org/>
                  V B <URL:http://classicvb.org/petition/>

                  Comment

                  • nime

                    #10
                    Re: WebBrowser1.Doc umentText

                    Document.Body.o uterHTML gets reformatted / non-original
                    and INCOMPLETE html code. Looks like buggy : (




                    "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atwrot e in message news:eDJSkOdnGH A.2264@TK2MSFTN GP04.phx.gbl...
                    "nime" <ea2005@planev. comschrieb:
                    >How can I grab html source of a frame?
                    >>
                    >I can retrive main frame by WebBrowser1.Doc umentText
                    >but I want to retrive inner (child) frame...
                    >>
                    >WebBrowser1.Do cument.Window.F rames(0).Docume ntText like thing doesn't exist...
                    >
                    \\\
                    For Each Frame As HtmlWindow In Me.WebBrowser1. Document.Window .Frames
                    MsgBox(Frame.Do cument.All(1).O uterHtml)
                    Next Frame
                    ///
                    >
                    --
                    M S Herfried K. Wagner
                    M V P <URL:http://dotnet.mvps.org/>
                    V B <URL:http://classicvb.org/petition/>

                    Comment

                    • Cor Ligthert [MVP]

                      #11
                      Re: WebBrowser1.Doc umentText


                      "Document.Body. outerHTML gets reformatted / non-original
                      and INCOMPLETE html code. Looks like buggy : (
                      >
                      No it gives complete HTML code however not always everything on a page.

                      Cor


                      Comment

                      • nime

                        #12
                        Re: WebBrowser1.Doc umentText

                        I mean webbrowser1.doc ument.body.inne rHTML has a bug here

                        innerHTML contains no form and I cannot fill the fields....

                        I've checked url, and compared the html code. Webbrowser1
                        reformats the tags and removes many lines. I call it as bug,
                        my form has been cropped : (

                        Then I tried Mozilla control, it has no problem, it parses everything
                        with no loss, but I couldn't use it, for example document.all.co unt
                        had an error...




                        "Cor Ligthert [MVP]" <notmyfirstname @planet.nlwrote in message news:%23YPiSren GHA.4572@TK2MSF TNGP05.phx.gbl. ..
                        >
                        "Document.Body. outerHTML gets reformatted / non-original
                        >and INCOMPLETE html code. Looks like buggy : (
                        >>
                        No it gives complete HTML code however not always everything on a page.
                        >
                        Cor
                        >

                        Comment

                        • Herfried K. Wagner [MVP]

                          #13
                          Re: WebBrowser1.Doc umentText

                          "nime" <ea2005@planev. comschrieb:
                          >I mean webbrowser1.doc ument.body.inne rHTML has a bug here
                          >
                          innerHTML contains no form and I cannot fill the fields....
                          >
                          I've checked url, and compared the html code. Webbrowser1
                          reformats the tags and removes many lines. I call it as bug,
                          my form has been cropped : (
                          Maybe HTML Internet Explorer doesn't understand gets stripped from the
                          output and the result is simply the serialized part of the DOM tree.

                          --
                          M S Herfried K. Wagner
                          M V P <URL:http://dotnet.mvps.org/>
                          V B <URL:http://classicvb.org/petition/>

                          Comment

                          • nime

                            #14
                            Re: WebBrowser1.Doc umentText

                            But the browser's itself displays the form in my app ???

                            I've got another problem with Mozilla control. I cannot fill the form fields which they exist.

                            AxMozillaBrowse r1.Document.All .Item("login"). Value = "xx"

                            line causes this error:

                            A first chance exception of type 'System.Runtime .InteropService s.COMException' occurred in mscorlib.dll


                            Private Sub AxMozillaBrowse r1_DocumentComp lete(ByVal sender As Object, ByVal e As
                            AxMOZILLACONTRO LLib.DWebBrowse rEvents2_Docume ntCompleteEvent ) Handles AxMozillaBrowse r1.DocumentComp lete

                            If e.uRL.ToString = "http://www.domain.com/login.asp" Then
                            AxMozillaBrowse r1.Document.All .Item("login"). Value = "xx"
                            AxMozillaBrowse r1.Document.All .Item("pass").V alue = "xxx"

                            End If

                            End Sub

                            "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atwrot e in message news:uKLqzNfnGH A.3896@TK2MSFTN GP05.phx.gbl...
                            "nime" <ea2005@planev. comschrieb:
                            >>I mean webbrowser1.doc ument.body.inne rHTML has a bug here
                            >>
                            >innerHTML contains no form and I cannot fill the fields....
                            >>
                            >I've checked url, and compared the html code. Webbrowser1
                            >reformats the tags and removes many lines. I call it as bug,
                            >my form has been cropped : (
                            >
                            Maybe HTML Internet Explorer doesn't understand gets stripped from the output and the result is simply the serialized part of the
                            DOM tree.
                            >
                            --
                            M S Herfried K. Wagner
                            M V P <URL:http://dotnet.mvps.org/>
                            V B <URL:http://classicvb.org/petition/>

                            Comment

                            • nime

                              #15
                              Re: WebBrowser1.Doc umentText

                              1. Mozilla Activex control doesn't support all of
                              properties/methods/elements/etc.

                              2. IE WebBrowser control did not fire because I've blocked a few IP's
                              (via hosts file) and an ad related inner frame couldnt complete. So
                              WebBrowser1_Doc umentComplete event did not fire. Now
                              I did unblock the IPs and event has been called again.

                              3. Now I have a new problem. Can you please read the topic:
                              WebBrowser: Programmaticaly click an image button ?

                              Thank you.



                              "nime" <ea2005@planev. com>, haber iletisinde þunlarý
                              yazdý:u1HK8RfnG HA.2420@TK2MSFT NGP03.phx.gbl.. .
                              But the browser's itself displays the form in my app ???
                              >
                              I've got another problem with Mozilla control. I cannot fill the form
                              fields which they exist.
                              >
                              AxMozillaBrowse r1.Document.All .Item("login"). Value = "xx"
                              >
                              line causes this error:
                              >
                              A first chance exception of type
                              'System.Runtime .InteropService s.COMException' occurred in mscorlib.dll
                              >
                              >
                              Private Sub AxMozillaBrowse r1_DocumentComp lete(ByVal sender As Object,
                              ByVal e As AxMOZILLACONTRO LLib.DWebBrowse rEvents2_Docume ntCompleteEvent )
                              Handles AxMozillaBrowse r1.DocumentComp lete
                              >
                              If e.uRL.ToString = "http://www.domain.com/login.asp" Then
                              AxMozillaBrowse r1.Document.All .Item("login"). Value = "xx"
                              AxMozillaBrowse r1.Document.All .Item("pass").V alue = "xxx"
                              >
                              End If
                              >
                              End Sub
                              >
                              "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atwrot e in message
                              news:uKLqzNfnGH A.3896@TK2MSFTN GP05.phx.gbl...
                              >"nime" <ea2005@planev. comschrieb:
                              >>>I mean webbrowser1.doc ument.body.inne rHTML has a bug here
                              >>>
                              >>innerHTML contains no form and I cannot fill the fields....
                              >>>
                              >>I've checked url, and compared the html code. Webbrowser1
                              >>reformats the tags and removes many lines. I call it as bug,
                              >>my form has been cropped : (
                              >>
                              >Maybe HTML Internet Explorer doesn't understand gets stripped from the
                              >output and the result is simply the serialized part of the DOM tree.
                              >>
                              >--
                              >M S Herfried K. Wagner
                              >M V P <URL:http://dotnet.mvps.org/>
                              >V B <URL:http://classicvb.org/petition/>
                              >
                              >



                              Comment

                              Working...