How to retrieve source of website

Thei

Newcomer
Joined
Aug 9, 2006
Messages
13
Hi all,

I was wondering if it is possible to retrieve the complete HTML source (like the View Source option in the internet explorer) of a website using the WebBrowser control in VS2005?

Thanks,

Thei
 
Yes marble_eater, thank you!

Perhaps you can also help me with the following? Is it possible to find a certain word within a document (using the same WebBrowser control) and select that word using code in order to use the ExecCommand method?
 
I've solved the problem. See the code below (object wb = WebBrowser control).

Code:
        Dim strSource As String = wb.DocumentText.ToString
        Dim intPos As Integer = Strings.InStr(strSource, "</title>", CompareMethod.Text)

        If intPos <> 0 Then
            Dim strTempSource As String = String.Empty

            strTempSource = Strings.Mid(strSource, 1, intPos - 1) & "</title><script language='JavaScript'>function SelectText(pValue) {var r = document.body.createTextRange(); var t = r.findText(pValue); if (t == true) {r.select();} return t;}</script>" & Strings.Mid(strSource, intPos + 8, Strings.Len(strSource)) '+ 8 is length of text </title>.

            wb.Document.Write(strTempSource)

            Dim Cnt As Integer = UBound(arrFind) + 1
            Dim i As Integer

            For i = 1 To Cnt
                Dim arrObj(0) As Object
                Dim bolSuccess As Boolean

                arrObj(0) = CObj(New String(arrFind(i - 1).ToString))

                With wb.Document
                    bolSuccess = .InvokeScript("SelectText", arrObj)

                    If bolSuccess = True Then
                        .ExecCommand("ForeColor", False, "#FF0000")
                        .ExecCommand("BackColor", False, "#FFFF00")
                        .ExecCommand("Unselect", False, Nothing)
                    End If
                End With
            Next
        End If
 
Back
Top