用我这个试试
Public Function GetBody(ByVal URL$,Optional ByVal Coding$ = "GB2312") Dim ObjXML On Error Resume Next Set ObjXML = CreateObject("Microsoft.XMLHTTP") With ObjXML .Open "Get",URL,False,"","" .setRequestHeader "If-Modified-Since","0" .Send GetBody = .responseBody End With GetBody = BytesToBstr(GetBody,Coding) Set ObjXML = Nothing End Function Public Function BytesToBstr(strBody,CodeBase) Dim ObjStream Set ObjStream = CreateObject("Adodb.Stream") With ObjStream .Type = 1 .Mode = 3 .Open .Write strBody .Position = 0 .Type = 2 .Charset = CodeBase BytesToBstr = .ReadText .Close End With Set ObjStream = Nothing End Function
注意第一行代码中Coding$ = "GB2312" 表示获取的网页内容为GB2312编码格式,如果出现乱码,那么就换成Coding$ = "utf-8"
返回值为:
a = GetBody("http://www.baidu.com")
也有人说
strconv( .responseBody,vbUnicode) 就可以了