Private Sub Form_Load()
a = getHTTPPage(“http://www.baidu.com/”)
b = Split(a, “[”)(1)
c = Split(b, “]”)(0)
MsgBox c
End Sub
Function getHTTPPage(url)
On Error Resume Next
Dim http
Set http = CreateObject(“MSXML2.XMLHTTP”)
http.Open “GET”, url, False
getHTTPPage = http.Send()
'MsgBox http.ReadyState
If http.ReadyState <> 4 Then
MsgBox “无法连接服务器”
Exit Function
End If
getHTTPPage = BytesToBstr(http.responseBody, “GB2312”)
Set http = Nothing
End Function
Function BytesToBstr(body, Cset)
Dim objstream
Set objstream = CreateObject(“adodb.stream”)
objstream.Type = 1
objstream.Mode = 3
objstream.Open
objstream.Write body
objstream.position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
Set objstream = Nothing
End Function
网络爬虫尝试(VB编写)
最新推荐文章于 2020-04-23 23:13:19 发布