I found the RFT control to save webbrowse text TXTHTML is richtextboxtXthtml.text = webbrowser1.document.body.innerText'Flag: rsftext Save as TXT file, Strtmp file path TXTHTML.SAVEFILETRTMP, RTFText
Set its Name property to Web
Private submmand1_click () web.navigate "www.google.com" End Sub
Private Sub web_DocumentComplete (ByVal pDisp As Object, URL As Variant) Set doc = web.DocumentFor Each i In doc.All msgbox typename (i) Text1.Text = Text1.text & vbclrf & i.innertextNextEnd sub
============================================================================================================================================================================================================= ========================================== reprinted
'Quote Microsoft HTML Object Library
Dim oDoc As HTMLDocument 'obtaining the document object Set oElement = oDoc.getElementById ( "T1")' Dim oElement As Object Dim oTxtRgn As Object Dim sSelectedText As String Set oDoc = WebBrowser1.Document obtained ID = "T1" object Set oTxtRgn = oDoc .SeLection.createRange 'gets the currently selected area object sSelectedText = OTRGN.TEXT' Select zone text assignment
Olement.focus' "T1" object gets focus
Olement.select 'alllective object "T1"
Debug.print "You have chosen text:" & sSelectedText
There is also other functions, huh, this. Streamlined look like this: Dim oDoc As Object Dim oTxtRgn As Object Dim sSelectedHTML As String Set oDoc = WebBrowser1.Document 'get the Document Object Set oTxtRgn = oDoc.selection.createRange' area of the object sSelectedHTML obtain documents currently being selected = oTxtRgn.htmlText ' Select Area Text Assignment Text1.Text = SSELECTEDHTML 'Text Box Display Capture HTML Source Code ...' or Continue Analysis Source Code
============================================================================================================================================================================================================= =================================================
I use WebBrowser to get the web source code, running directly, but after compiling the error private sub command1_click () webbrowser1.navigate "http://www.sdqx.gov.cn/sdcity.php"end Sub
Private sub webbrowser1_download limited () page Download Download DIM DOC, OBJHTMLSET DOC = WebBBROWSER1.DOCUMENT
Set objhtml = doc.body.createtextRange () if not isnull (ipjhtml) ThenText1.text = objhtml.htmltextende
End Sub
I use WebBrowser to get the web source code, running directly, but after compiling
Tip: Real-time error "91" Object variables or with block variables are not set, no settings may be caused,
Private sub webbrowser1_downloaduniccomplete () if WebBrowser.busy = false thndim doc, objhtmlset doc = WebBBROWSER1.DOCUMENT
Set objhtml = doc.body.createtextRange () if not isnull (objhtml) TENTEXT1.TEXT = Objhtml.htmlTextend IFEND IFEND SUB
You have to get the web source code is better to use XMLHTTP.
Quote MSXML first
DIM X as new msxml2.xmlhttp x.open "get", "http://www.sina.com", false x.send
Msgbox strconv (x.responsebody, vbunicode) ========================================= ============================================================================================================================================================================================================= ==== I found online using rft controls save webbrowse text txtHtml is RichTextBoxtxtHTML.Text = WebBrowser1.document.body.innerText'flag: rsftext saved as a txt file, strtmp file path txtHTML.saveFile strtmp, rtfText
============================================================================================================================================================================================================= ====================================
Private Sub WebBrowser1_DownloadComplete () Dim objHtml As Object 'download completion status bar displays "Link Finished" Set objHtml = Me.WebBrowser1.Document.Body.Createtextrange () If Not IsNull (objHtml) Then Text1.Text = objHtml.htmltext End IfEnd Sub use inet control Source1 = Inet1.OpenURL ( "www.9cbs.net") If Source1 <> "" ThenRichTextBox1.Text = Source1Me.Inet1.CancelElseSource = MsgBox ( "Source code is not available.", vbInformation, "Source code ") END IF
Private sub fascist1_click () text1.text = webbrowser1.document.body.innerhtmlend Sub
============================================================================================================================================================================================================= ================================ Add Timer, CommandButton, TextPrivate Sub Command1_Click () WebBrowser1.navigate http: // www . Sohu.com / Timer1.enabled = truend subsprivate sub timer1_timer () DIM DOC, OBJHTML AS Objectdim i as integerim strHtml as string
if not webbrowser1.busy thenset doc = webbrowser1.documenti = 0set objhtml = doc.body.createtextrange () if not isnull (objhtml) thentext1.text = objhtml.htmltextend iftimer1.enabled = falseend ifend sub
Dim doc, objhtml As ObjectIf Not webbrowser1.Busy Then Set doc = webbrowser1.Document Set objhtml = doc.body.createtextrange () If Not IsNull (objhtml) Then text1.text = objhtml.htmltext End If Set doc = Nothing Set objhtml = Nothing
END IF
============================================================================================================================================================================================================= ================================================== or Try with InternetReadFile, you can also: Option Explicit
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (_ ByVal sAgent As String, ByVal lAccessType As Long, _ ByVal sProxyName As String, ByVal sProxyBypass As String, _ ByVal lFlags As Long) As LongPrivate Declare Function InternetOpenUrl Lib " wininet.dll "Alias" InternetOpenUrlA "(_ ByVal hInternetSession As Long, ByVal sUrl As String, _ ByVal sHeaders As String, ByVal lHeadersLength As Long, _ ByVal lFlags As Long, ByVal lContext As Long) As LongPrivate Declare Function InternetReadFile Lib" wininet .dll "(_ ByVal hFile As Long, ByVal sBuffer As String, _ ByVal lNumBytesToRead As Long, _ lNumberOfBytesRead As Long) As IntegerPrivate Declare Function InternetCloseHandle Lib" wininet.dll "(_ ByVal hInet As Long) As IntegerPrivate Const INTERNET_FLAG_NO_CACHE_WRITE = & H400 0000dim s
Private Function GetUrlFile (stUrl As String) As String Dim lgInternet As Long, lgSession As Long Dim stBuf As String * 1024 Dim inRes As Integer Dim lgRet As Long Dim stTotal As String stTotal = vbNullString lgSession = InternetOpen ( "VBTagEdit", 1, vbNullString , vbNullString, 0) If lgSession Then lgInternet = InternetOpenUrl (lgSession, stUrl, vbNullString, _ 0, INTERNET_FLAG_NO_CACHE_WRITE, 0) If lgInternet Then Do inRes = InternetReadFile (lgInternet, stBuf, 1024, lgRet) stTotal = stTotal & Mid $ (stBuf, 1, lgRet) Loop While (lgRet <> 0) End If inRes = InternetCloseHandle (lgInternet) End If GetUrlFile = stTotalEnd FunctionPrivate Sub Command1_Click () Text1.Text = GetUrlFile ( "http://adsl.tsee.net/teleplay/view .asp? id = 143 ") End Sub
============================================================================================================================================================================================================= ============================================================================================================================================================================================================= =
Set vdoc = webbrowser1.document 'Get the source code for the web page for Each O in vdoc.all doevents HTMLPage = HTMLPage & O.innerHTMLNEXT then writes the HTMLPage content in the .html file if this page contains frames if this page is written to .html file. Then you have to process the box.