是只保存网页中的文本吗?用下面的代码试试:(需要添加一个WebBrowser控件,名称为web) Private Sub Command1_Click() Web.Navigate "www.google.com" End SubPrivate Sub web_DocumentComplete(ByVal pDisp As Object, URL As Variant) Dim doc, i Dim s Set doc = Web.Document For Each i In doc.All s = s & vbCrLf & i.innertext Next Open "d:\网页内容.txt" For Output As #1 Print #1, s Close #1 End Sub 以上代码功能为:点击按钮Command1以后打开www.google.com,并把网页中的文本保存到文本文件d:\网页内容.txt中。
Private Sub Command1_Click()
Web.Navigate "www.google.com"
End SubPrivate Sub web_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim doc, i
Dim s
Set doc = Web.Document
For Each i In doc.All
s = s & vbCrLf & i.innertext
Next
Open "d:\网页内容.txt" For Output As #1
Print #1, s
Close #1
End Sub
以上代码功能为:点击按钮Command1以后打开www.google.com,并把网页中的文本保存到文本文件d:\网页内容.txt中。
就是说,form 上面不要放 WebBrowser 控件。明白?
再次感谢你的答复!
不过为什么不用WebBrowser控件呢?这虽然不是VB的标准自带控件,但是并不影响程序的通用性,因为只要安装了IE就会有这个控件;如果是因为界面上不能有这个控件,则完全可以用WebBrowser1.move 1000000,1000000这样的代码来把控件放到可视区域之外;如果是因为速度的问题,这倒是确实存在的,用WebBrowser控件获取html代码比inet、winsock等方法都慢,不过楼主也可以再自己搜索一下如何让WebBrowser不下载网页中的影音图片等元素来解决这个问题。