Thei Posted September 7, 2009 Posted September 7, 2009 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 Quote
Leaders snarfblam Posted September 7, 2009 Leaders Posted September 7, 2009 Is what you are looking for the WebBrowser.DocumentText property? Quote [sIGPIC]e[/sIGPIC]
Thei Posted September 8, 2009 Author Posted September 8, 2009 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? Quote
Thei Posted September 8, 2009 Author Posted September 8, 2009 I've solved the problem. See the code below (object wb = WebBrowser control). 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.