我要把html的源文件导入到一个字符串中进行解析. 但是有些网页中的charset编码方式会导致转换后的字符串出现乱码(如charset=UTF-8), 不知道有谁统计过,哪些charset会导致乱码出现, 是否只有一个utf-8会出现这种情况? 示例代码如下:
fn = VBA.FreeFile strText = VBA.String(VBA.FileLen(strHtmlFileName), " ")
Open strHtmlFileName For Binary As #fn
Get #fn, , strText
Close #fn debug.print strText '增加vbUnicode支持一样乱码.注:
编译平台: Visual Basic 6.0. 要求兼容win98 and above.
客户: 全球, 不仅仅国内. (所以各种charset、语言都可能遇到)
fn = VBA.FreeFile strText = VBA.String(VBA.FileLen(strHtmlFileName), " ")
Open strHtmlFileName For Binary As #fn
Get #fn, , strText
Close #fn debug.print strText '增加vbUnicode支持一样乱码.注:
编译平台: Visual Basic 6.0. 要求兼容win98 and above.
客户: 全球, 不仅仅国内. (所以各种charset、语言都可能遇到)
Set oStream = New ADODB.Stream
oStream.Type = adTypeText
oStream.Charset = "UTF-8" ' 修改成适当的 Charset
oStream.Open
oStream.LoadFromFile strHtmlFileName
Debug.Print oStream.ReadText()
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">为何不用 Microsoft HTML Object Library?
我需要把解析后的内容分类处理后显示给用户, 最终内容要显示在treeview及listview中. 处理charset是必然的
一般情况下操作系统都带了 ADO 的,不需要单独安装。
另外还可以选择 Scripting Runtime,这个也是系统自带的。