我在网上找到使用rft控件保存webbrowse文本
txtHTML.Text = WebBrowser1.document.body.innerText
´flag :rsftext 保存为txt文件,strtmp文件路径
txtHTML.saveFile strtmp,rtfText
将其name属性设置为web
Private Sub Command1_Click()
End Sub
Private Sub web_DocumentComplete(ByVal pDisp As Object,URL As Variant)
Set doc = web.Document
For Each i In doc.All
Next
End sub
===========================================================================================
转载
´引用 Microsoft HTML Object Library
上面这段儿还附送了其他功能,呵呵。精简一下是这样:
==================================================================================================
我用WebBrowser取得网页源码,直接运行正常,但在编译后出错
Private Sub Command1_Click()
WebBrowser1.Navigate ""
End Sub
Private Sub WebBrowser1_DownloadComplete()
´页面下载完毕
Dim doc,objhtml
Set doc = WebBrowser1.Document
Set objhtml = doc.body.createtextrange()
If Not IsNull(objhtml) Then
Text1.Text = objhtml.htmltext
End If
End Sub
我用WebBrowser取得网页源码,直接运行正常,但在编译后出错
提示:实时错误“91”
可能是没有下载完所致,
Private Sub WebBrowser1_DownloadComplete()
if webbrowser.busy=false then
Dim doc,objhtml
Set doc = WebBrowser1.Document
Set objhtml = doc.body.createtextrange()
If Not IsNull(objhtml) Then
Text1.Text = objhtml.htmltext
End If
end if
End Sub
你要得网页源码用 xmlhttp比较好
先引用 msxml
Dim x As New MSXML2.XMLHTTP
MsgBox StrConv(x.responseBody,vbUnicode)
===============================================================================================
我在网上找到使用rft控件保存webbrowse文本
txtHTML.Text = WebBrowser1.document.body.innerText
´flag :rsftext 保存为txt文件,strtmp文件路径
txtHTML.saveFile strtmp,rtfText
=====================================================================================
Private Sub WebBrowser1_DownloadComplete()
End Sub
使用inet控件
Source1 = Inet1.OpenURL("")
If Source1 <> "" Then
RichTextBox1.Text = Source1
Me.Inet1.Cancel
Else
Source = MsgBox("Source code is not available.",vbInformation,"Source Code")
End If
Private Sub Command1_Click()
End Sub
==================================================================================
加入timer,commandbutton,text
private sub command1_click()
webbrowser1.navigate
timer1.enabled=true
end sub
private sub timer1_timer()
dim doc,objhtml as object
dim i as integer
dim strhtml as string
if not webbrowser1.busy then
set doc=webbrowser1.document
i=0
set objhtml=doc.body.createtextrange()
if not isnull(objhtml) then
text1.text=objhtml.htmltext
end if
timer1.enabled=false
end if
end sub
Dim doc,objhtml As Object
If Not webbrowser1.Busy Then
End If
===================================================================================================
或者试试用InternetReadFile,效果也可以:
Option Explicit
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" ( _
Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" ( _
Private Declare Function InternetReadFile Lib "wininet.dll" ( _
Private Declare Function InternetCloseHandle Lib "wininet.dll" ( _
Private Const INTERNET_FLAG_NO_CACHE_WRITE = &H4000000
Dim s
Private Function GetUrlFile(stUrl As String) As String
End Function
Private Sub Command1_Click()
End Sub
=====================================================================================================
Set vDoc = WebBrowser1.Document ´获取网页的源码 For Each o In vDoc.All DoEvents htmlpage = htmlpage & o.innerHTML Next 然后用写二进制文件的方法将htmlpage的内容写入到.html文件中如果这个网页中含有框架那么要对框加进行处理。