VB 获取网页源码后乱码问题

前端之家收集整理的这篇文章主要介绍了VB 获取网页源码后乱码问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
utf-8 编码问题
用我这个试试
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) 就可以了

猜你在找的VB相关文章