推荐于2016-03-25
展开全部
'引用XML2
Option Explicit
Private Sub Command1_Click()
Text2.Text = GetPage(Text1.Text)
End Sub
Function GetPage(url)
On Error Resume Next
Dim Retrieval
Set Retrieval = CreateObject("Msxml2.XMLHTTP")
With Retrieval
.Open "Get", url, False, "", ""
.send
If .readyState = 4 Then
If Len(.responseBody) = 0 Then
Debug.Print "<h1>服务器故障~!~~~~</h1>"
Else
GetPage = BytesToBstr(.responseBody)
End If
End If
End With
Set Retrieval = Nothing
On Error GoTo 0
End Function
Function BytesToBstr(body)
Dim objstream
Set objstream = CreateObject("adodb.stream")
With objstream
.Type = 1
.Mode = 3
.Open
.Write body
.Position = 0
.Type = 2
.Charset = "UTF-8" '如果有乱码,手动打开网页源代码,看是什么编码的,修改成GB2312试试
BytesToBstr = objstream.ReadText
.Close
End With
Set objstream = Nothing
End Function
追问
text2 获得源代码,第一个function是提取源代码,这些我看明白了,第二个function是什么意思啊?
追答
第二个主要作用是转编码的,这样就不会有乱码了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询