首先建立一个模块: Function GetPage(Url, LG) On Error GoTo Exittag: Dim Retrieval As Object Set Retrieval = CreateObject("Microsoft.XMLHTTP") With Retrieval .Open "GET", Url, False, "", "" .Send GetPage = BytesToBstr(.responseBody, LG) End With Set Retrieval = Nothing Exit Function Exittag: 'MsgBox "对不起,查询超时,请确保您的网络或目标主机网络是否正常!" Err.Clear End Function Public 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 Function GetKey(HTML, Start, Last) Dim Filearray, Filearray2 On Error Resume Next Filearray = Split(HTML, Start) Filearray2 = Split(Filearray(1), Last) GetKey = Filearray2(0) End Function 窗口代码: Private Sub Command1_Click() MsgBox GetKey(GetPage("http://user.qbar.qq.com/" & text1.text & "/", "GB2312"),"<h3><strong>","<span>") End Sub
Function GetPage(Url, LG)
On Error GoTo Exittag:
Dim Retrieval As Object
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "GET", Url, False, "", ""
.Send
GetPage = BytesToBstr(.responseBody, LG)
End With
Set Retrieval = Nothing
Exit Function
Exittag:
'MsgBox "对不起,查询超时,请确保您的网络或目标主机网络是否正常!"
Err.Clear
End Function
Public 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
Function GetKey(HTML, Start, Last)
Dim Filearray, Filearray2
On Error Resume Next
Filearray = Split(HTML, Start)
Filearray2 = Split(Filearray(1), Last)
GetKey = Filearray2(0)
End Function
窗口代码:
Private Sub Command1_Click()
MsgBox GetKey(GetPage("http://user.qbar.qq.com/" & text1.text & "/", "GB2312"),"<h3><strong>","<span>")
End Sub