asp抓取utf-8网页时出现乱码,怎么办?
functiongetHTTPPage(url)dimHttponerrorresumenextsetHttp=server.createobject("MSXML2.X...
function getHTTPPage(url)
dim Http
on error resume next
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
If err then
err.clear
Set Http=Nothing
Exit function
End If
Http.send()
if Http.readystate<>4 then
Set Http=Nothing
Exit function
end if
If Http.Status<>200 then
Set Http=Nothing
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
高手写下,学习中
这样可以 但是gb2312 的网页又有问题 展开
dim Http
on error resume next
set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",url,false
If err then
err.clear
Set Http=Nothing
Exit function
End If
Http.send()
if Http.readystate<>4 then
Set Http=Nothing
Exit function
end if
If Http.Status<>200 then
Set Http=Nothing
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
高手写下,学习中
这样可以 但是gb2312 的网页又有问题 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询