1,502
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Private objstream As ADODB.Stream
Private retrieval As New XMLHTTP '新建XMLHTTP对象
Private Sub Form_Load()
Set objstream = New ADODB.Stream
MsgBox GetPage("http://www.baidu.com")
End Sub
Private Function GetPage(Url)
On Error Resume Next
Set retrieval = New MSXML2.XMLHTTP
retrieval.Open "GET", Url, False
If Err <> 0 Then
MsgBox "错误!"
End If
retrieval.send
If Err.Number <> 0 Then '未找到服务器!
GetPage = "ERROR"
Else
GetPage = BytesToBstr(retrieval.responseBody) '成功获取网页源码!
End If
End Function
Private Function BytesToBstr(body) '用于处理编程转换
On Error Resume Next
objstream.Type = 1
objstream.Mode = 3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = "GB2312"
BytesToBstr = objstream.ReadText
objstream.Close
End Function