〓〓〓〓〓〓〓〓〓关于用XMLHTTP提取网页乱码问题,在线等解决〓〓〓〓〓〓〓〓〓〓〓〓

ldsfiio_dd 2006-02-27 04:40:41
我一个页面中比如a.asp中用的是gb2312,这个页面里有个表格显示的是抓取另一个页面b.asp的某一部分内容(不含b.asp的头信息,只是抓取它中间某一部分内容),b.asp用的是utf8的编码,现在a.asp里其他的内容都是正常的 唯独抓取的那部分内容是乱码,请问该如何解决?
我抓取的代码:
On Error Resume Next
Function getHTTPPage(url)
Dim Http
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
Http.send()
If Http.readystate<>4 then
exit function
End If
getHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
set Http=nothing
If err.number<>0 Then err.Clear
End Function
Function BytesToBstr(body,Cset)
Dim objstream
set objstream = Server.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
...全文
164 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
jspadmin 2006-02-28
  • 打赏
  • 举报
回复
试试页面顶部加上codepage=936
quzhizenmegao 2006-02-27
  • 打赏
  • 举报
回复
还是无法将utf-8转化成到gb里,gb页面里还是乱码,
哎 晚上睡不着了 :(
sungcong 2006-02-27
  • 打赏
  • 举报
回复
如果A页面用JAVASCRIPT,B页面用ASP,那么又如何解决utf-8转gb2312这个问题呀?
  • 打赏
  • 举报
回复
?
quzhizenmegao 2006-02-27
  • 打赏
  • 举报
回复
晕了 还是不行 用了楼上的方法 和我下面的函数出错 无效的 mid
  • 打赏
  • 举报
回复
Function bin2str(binstr)
Dim varlen,clow,ccc,skipflag
'中文字符Skip标志
skipflag=0
ccc = ""
If Not IsNull(binstr) Then
varlen=LenB(binstr)
For i=1 To varlen
If skipflag=0 Then
clow = MidB(binstr,i,1)
'判断是否中文的字符
If AscB(clow) > 127 Then
'AscW会把二进制的中文双字节字符高位和低位反转,所以要先把中文的高低位反转
ccc =ccc & Chr(AscW(MidB(binstr,i+1,1) & clow))
skipflag=1
Else
ccc = ccc & Chr(AscB(clow))
End If
Else
skipflag=0
End If
Next
End If
bin2str = ccc
End Function
function utf2str(binstr)
quzhizenmegao 2006-02-27
  • 打赏
  • 举报
回复
还是不行啊,我本来的页面是gb2312的,抓取的时候我只抓取对方页面body的部分,现在如果对方也是gb2312的就没错,如果是uft-8的 就是乱码,我用了楼上两位的还是乱码阿,到底怎么回事?
jspadmin 2006-02-27
  • 打赏
  • 举报
回复
将抓取的那部分要使用楼上两位提供的函数转换为gb2312
KimSoft 2006-02-27
  • 打赏
  • 举报
回复
哈哈,我也有一样的代码:

<%
Function GetHttpPage(url)

On Error Resume Next

Dim Http
Set Http = Server.CreateObject("Microsoft.XMLHTTP")
Http.open "GET", url, False
Http.send()

If Http.readystate <> 4 Then
Exit Function
End If

GetHttpPage = Bytes2BSTR(Http.ResponseBody)
Set Http = Nothing

If Err.Number <> 0 Then Err.Clear

End Function

Function Bytes2BSTR(vIn)

Dim strReturn
Dim i1, ThisCharCode, NextCharCode

strReturn = ""

For i1 = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn, i1, 1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn, i1 + 1, 1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i1 = i1 + 1
End If
Next

Bytes2BSTR = strReturn

End Function
%>
meizz 2006-02-27
  • 打赏
  • 举报
回复
Function bytes2BSTR(vIn)
dim i, strReturn, ThisCharCode, NextCharCode
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧